Monday, December 7, 2015

Avoid strange weird characters when sending mail through PHPMailer

Avoid strange weird characters when sending mail through PHPMailer

From the Outlook for Mac forum on Microsoft Answers:

From a little time, I have this problem.
Some messages are with strange characters.
Here an example, but sometimes a messages contains a lot of characters like that.
The word is HCI and then there is a S with an accent !!!

Why does this happen?

This is a text encoding problem that occurs when the sending email server is converting a message to send to another mail server. And it only affects plain text messages not HMTL formatted messages.

Not all service providers use the same mail server software and not all software plays nicely with each other. Therefore, an outgoing mail server (aka SMTP server) must convert an email message to a common format before relaying to the recipient’s email server. Generally, it’ll rely on the sending email application to tell it the best format.

Some servers such as Exchange (including Office 365) may decide the text encoding if it doesn’t recognize the one specified by the email application but it doesn’t always decide correctly. The recipient then sees strange characters in the message. Curly quotes may change to numbers and ellipses may change to accented characters.


$mailer = new PHPMailer();

$mailer->CharSet = 'UTF-8';
$mailer->Encoding = 'base64';


No comments: