drakyoko
drakyoko

Reputation: 505

Send unicode emoji with PHPMailer

I'm trying to send unicode emoji trough PHPMailer (5.2) but the emails I sent are received with weird characters instead of emojis. I'm currently sending HTML emails where I just echo a string containing some utf-8 emoji and inspecting the email source the string seems to be printed correctly. For example:

echo "😁";

produces:

=F0=9F=98=81

in the email source code (which should be OK).

Upvotes: 5

Views: 5968

Answers (2)

William Entriken
William Entriken

Reputation: 39303

I needed to use the slightly different:

$mail = new PHPMailer();
$mail->CharSet = 'utf-8';

Upvotes: 1

drakyoko
drakyoko

Reputation: 505

It turns out that PHPMailer uses charset=iso-8859-1 by default in HTML emails (in the email header you'll find Content-Type: text/html; charset=iso-8859-1 while you should use UTF-8: Content-Type: text/html; charset=UTF-8.

You can set the charset in PHPMailer by doing:

$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';

Upvotes: 11

Related Questions