Problems with the accents in the subject of PHPMailer

1

I am using PHPMailer to send emails for password recovery, welcome ... etc. The fact is that the body of the message is correctly coded by applying $mail->CharSet = 'UTF-8'; but the subject of the message does not recognize the accents, so they come to me without subject.

Here I paste the code:

require("../phpmail/class.phpmailer.php");
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Mailer="smtp";
$mail->SMTPAuth = true;
$mail->Host = "XXXXX"; 
$FromServ = "XXXXX";
$mail->Username = "XXXXX"; 
$mail->Password = "XXXXX"; 
$mail->Port = 587; 
$mail->From = "XXXXX";; 
$mail->Timeout=60;
$mail->Sender = "XXXXX";;
$mail->FromName = "XXXXX"; 
$mail->AddAddress($email);
$mail->IsHTML(true); 
$subject = "Recuperar contraseña";   // << No reconoce la Ñ 
$mail->Subject = $subject; 
$body= '  AQUÍ EL MENSAJE';  
'

If anyone knows how I can do to correctly code the matter, I would do myself a great favor. I have already applied rules like utf8_decode () and all it does is change the Ñ to a question mark (Recover password).

Thank you all in advance.

    
asked by Ander 10.09.2018 в 12:02
source

1 answer

2

Usually this is resolved by decoding the content before setting the Subject of the mail object:

$subject = "Recuperar contraseña";
$subject = utf8_decode($subject);
$mail->Subject = $subject;

And then set the character set ( Charset ) of the mail object:

$mail->CharSet = 'UTF-8';
    
answered by 10.09.2018 в 12:26