Skip to content
Advertisement

PHPMailer character encoding issues

I try to use PHPMailer to send registration, activation. etc mail to users:

JavaScript

The $message contains latin characters. Unfortunately all webmail (gmail, webmail.mydomain.org, emailaddress.domain.xx) is using a different coding.

How can I force to use UTF-8 coding to show my mail exactly the same on all mailboxes?

I tried to convert the mail header width mb_convert_encoding(), but without luck.

Advertisement

Answer

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

JavaScript

Should be replaced by:

JavaScript

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:

JavaScript

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.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement