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′ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=utf-8′ . “\r\n”;
// Additional headers
$headers .= ‘To: zhoz <zhoz@example.com>’ . “\r\n”;
$headers .= ‘From: Admin <admin@example.com>’ . “\r\n”;
$headers .= ‘Reply-To: zhoz <zhoz@example>’ . “\r\n”;
mail($to, $subject, $message, $headers);
This entry was posted in PHP and tagged , . Bookmark the permalink.

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

  1. OROCHI says:

    啊 最近论坛开不了了 郁闷 = =

  2. OROCHI says:

    你用的哪的空间?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>