先用函数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);
Posted in PHP at December 30th, 2009. Trackback URI: trackback
Tags: ,

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

  1. December 30th, 2009 at 9:02 am #OROCHI

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

  2. December 30th, 2009 at 9:02 am #OROCHI

    你用的哪的空间?

Leave a Reply