PHP发邮件标题与内容乱码的解决方法

先用函数base64_encode() — 使用 MIME base64 对数据进行编码
标题字符串前加编码类型例如: =?UTF-8?B?
标题字符串后加:?=
邮件header指明Content-type: text/html; charset=utf-8,这样就能防止邮件正文乱码

$to         = ‘zhoz@example.com’;
$subject   = “=?UTF-8?B?”.base64_encode(‘邮件标题’).”?=”;
$headers   = ‘MIME-Version: 1.0’ . “rn”;
$headers .= ‘Content-type: text/html; charset=utf-8’ . “rn”;
// Additional headers
$headers .= ‘To: zhoz <zhoz@example.com>’ . “rn”;
$headers .= ‘From: Admin <admin@example.com>’ . “rn”;
$headers .= ‘Reply-To: zhoz <zhoz@example>’ . “rn”;
mail($to, $subject, $message, $headers);

Leave a Comment Cancel reply

Your email address will not be published.

*

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

3 Trackbacks