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

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

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>