PHP Mail_Mime:如何在电子邮件正文中正确使用encodeHeader()

时间:2014-04-21 15:32:54

标签: php email pear mime

如何修复此字符编码:

require_once(/Mail/mime.php");

$corpoTxt = 'Teste envio relatórios são';
$corpoHtml= '<html><body>Versão HTML do texto</body></html>';

我试过了:

$corpoTxt=$mime->encodeHeader("corpo", $corpoTxt, "utf-8", "quoted-printable");
$corpoHtml=$mime->encodeHeader("corpohtmls", $corpoHtml, "utf-8", "quoted-printable");

但它没有用,我得到了:

Versão HTML do texto

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

在调用$ mine-headers()函数之前尝试包含这些行。

# Ensure EML is UTF-8 compliant
$mimeparams["debug"] = "True";
$mimeparams['text_encoding'] = "8bit";
$mimeparams['text_charset'] = "UTF-8";
$mimeparams['html_charset'] = "UTF-8";
$mimeparams['head_charset'] = "UTF-8";
$mime->get($mimeparams);

这将确保您的UTF-8字符在EML中正确显示。最后,像这样保存TXT和HTML正文:

    $mime->setTXTBody($corpoTxt);
    $mime->setHTMLBody($corpoHtml);

那应该有用。如需更多帮助,请查看:

Pear Mail, how to send plain/text + text/html in UTF-8