如何使用Pear
正确设置多部分电子邮件的文本编码?
我看了很多例子,我相信我设置正确。然而,当发送电子邮件时,即使我指定UTF-8
,它们也会以charset=ISO-8859-1
到达。
当我决定发送包含文本和HTML部分的多部分电子邮件时,这个问题就开始了。我试着设置一个内容类型,但似乎没有什么不同。
下面是我使用的代码。欢迎提出建议。
function send_html_email($to, $from, $subject, $html, $plainTxt ) {
require_once "Mail.php";
require_once "Mail/mime.php";
$host = "ssl://secure.xxx.com";
$port = "xxx";
$username = "xxx";
$password = "xxx";
$headers = array (
'charset' => 'UTF-8',
'From' => $from,
'To' => $to,
'Subject' => $subject,
'MIME-Version' => "1.0"
);
$crlf = "'n";
$mime = new Mail_mime($crlf);
$mime->setHTMLBody($html);
$mime->setTXTBody($plainTxt);
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp', array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
}
试试这样的头:
$headers['Content-Type'] = "text/plain; charset='"UTF-8'"";
$headers['Content-Transfer-Encoding'] = "8bit";
参考:http://pear.php.net/manual/en/package.mail.mail.factory.php # 13207
作为旁注,Pear是"可重用PHP组件的框架和分发系统"。Mail组件只是Pear提供的众多组件之一。