PHP使用mail函数发送邮件标题乱码问题

80酷酷网    80kuku.com

  >

PHP程序使用mail()函数发送邮件的时候,标题中文的话会出现乱码。

解决方法:

先用函数base64_encode() — 使用 MIME base64 对数据进行编码

标题字符串前加编码类型例如: =?UTF-8?B?

标题字符串后加:?=

邮件header说明Content-type — 防止邮件正文也乱码

举例:

以下为引用的内容:

 $to         = 'xinpleexample.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: Xinple <xinpleexample.com>' . "rn";
$headers .= 'From: Admin <adminexample.com>' . "rn";
$headers .= 'Reply-To: Xinple <xinpleexample>' . "rn";
mail($to, $subject, $message, $headers);

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: