Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 433
drakyoko Avatar asked Sep 07 '16 09:09

drakyoko


1 Answers

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';
like image 118
drakyoko Avatar answered Sep 23 '22 10:09

drakyoko