您的位置:首页 > 编程语言 > PHP开发

解决php中用mail发邮件时标题出现乱码

2008-02-01 14:57 302 查看
php程序使用mail()函数发送邮件的时候,标题中文的话会出现乱码。

解决方法:

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

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

标题字符串后加:?=

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

$to = ‘xinple@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: Xinple <xinple@example.com>‘ . “\r\n“;
$headers .= ‘From: Admin <admin@example.com>‘ . “\r\n“;
$headers .= ‘Reply-To: Xinple <xinple@example>‘ . “\r\n“;
mail($to, $subject, $message, $headers);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: