邮件客户端中php的邮件功能编码错误(蝙蝠!)



我今天遇到了一个问题,花了两个小时。我使用了简单的邮件功能,它在gmail中运行良好,但在bat中运行良好!俄语字母编码错误。

if (isset($_POST['var'])) // condition that runs mail 
{
    mail("email@gmail.com", "Subject", "Message");// This works fine on gmail
    //mail("bat@mailservice.ru","Subject","Message");// Wrong encoding
}

问题是邮件客户端有另一种消息格式。要用正常编码发送此消息,您应该这样做主题:

$subject = "=?utf-8?b?".base64_encode("Subject")."?=";// or any other encoding which you use at your site
mail("bat@mailservice.ru",$subject,"Message");

此外,如果问题仍然存在,请尝试在php页面和元标签中添加带编码的标题:

php(在任何回波之前):

header('Content-type: text/html; charset=utf-8');

html(在页面的<head>处):

meta http-equiv='Content-Type' content='text/html; charset=utf-8'>

您还可以添加此发送头作为邮件功能的可选参数。

$header="MIME-Version: 1.0nContent-Type: text/plain; charset='utf-8'";
mail("bat@mailservice.ru",$subject,"Message",$header);

最新更新