Send unicode emoji with PHPMailer

余生长醉 提交于 2019-11-30 05:22:50

问题


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


回答1:


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';



回答2:


I needed to use the slightly different:

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


来源:https://stackoverflow.com/questions/39365797/send-unicode-emoji-with-phpmailer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!