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

3 Comments

 Add your comment
  1. 啊 最近论坛开不了了 郁闷 = =

  2. 我加了这段,但正文部分发送到新浪邮箱,新浪那边看到的还是乱码,用outlook等客户端下载来看,默认居然是GB2312,修改客户端修改成UTF-8后,部分字体可以显示,但部分依旧乱码
    $headers .= ‘Content-type: text/html; charset=utf-8′ . “rn”;

Leave a Comment

Your email address will not be published.

*