Phpmailer Character Encoding Issues

PHPMailer character encoding issues

If you are 100% sure $message contain ISO-8859-1 you can use utf8_encode as David says. Otherwise use mb_detect_encoding and mb_convert_encoding on $message.

Also take note that

$mail -> charSet = "UTF-8"; 

Should be replaced by:

$mail->CharSet = 'UTF-8';

And placed after the instantiation of the class (after the new). The properties are case sensitive! See the PHPMailer doc fot the list & exact spelling.

Also the default encoding of PHPMailer is 8bit which can be problematic with UTF-8 data. To fix this you can do:

$mail->Encoding = 'base64';

Take note that 'quoted-printable' would probably work too in these cases (and maybe even 'binary'). For more details you can read RFC1341 - Content-Transfer-Encoding Header Field.

Problems with PHP Mailer header encoding

Use

$mail->CharSet = 'UTF-8';

instead of

$mail->CharSet = "utf8";

PHPMailer and specific characters in subject (UTF-8?)

I'm not sure why you're trying to do things the hard way! The first step is setting the CharSet property to UTF-8, which you've done. For the subject, you have this:

$subject = 'RE: La plantation de votre arbre a commancé';
$sub = '=?UTF-8?B?'.base64_encode($subject).'?=';
$mail->Subject = $sub;

There's a lot of unnecessary stuff going on in there. All you need to do is:

$mail->Subject = 'RE: La plantation de votre arbre a commancé';

PHPMailer takes care of all the encoding for you. The only thing to be careful of here is to be sure that you are actually working in UTF-8 in your editor. If you're using ISO-8859-1 or similar, it won't work – though it will look identical in your code.

As for spelling mistakes, I'm going to have to leave them up to you...

PHPMailer not setting charset in header correctly

PHP is case-sensitive for property names, so change this:

$mail->charSet = 'UTF-8';

to

$mail->CharSet = 'UTF-8';

You might consider this as a hint to get a decent IDE, since any good one would have flagged this without you even running the code.

phpmailer subject from variable creates encoding issue

I found a solution, none of the html decoding functions were working so I wrote my own function for Turkish characters.

function replacehtml($inputText) {
$replace = array('İ','ı','Ö','ö','Ü','ü','Ç','ç','Ğ','ğ','Ş','ş');
$search = array('İ','ı','Ö','ö','Ü','ü','Ç','ç','Ğ','ğ','Ş','ş');
$outputText=str_replace($search, $replace, $inputText);
return $outputText;
}


Related Topics



Leave a reply



Submit