当用php的mail()函数发送邮件时,如果包含中文标题产生乱码,需要做以下处理即可解决:
$subject = '邮件标题中文-php-mail()函数';
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
对应的,邮件的header可以简单设置一下,以下举例说明发送一封邮件:
$mail = 'digdeeply@staff.sina.com.cn';
$text = "邮件正文content……";
$subject = 'IVR 内置控制平台定时脚本运行SQL错误';
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
$headers = 'From: You ' . "\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=uft-8' . "\r\n";
$headers .="Content-Transfer-Encoding: 8bit";
mail($mail, $subject, $text, $headers );
对邮件正文同样有效