PHP Mail_Mime:如何在电子邮件正文中正确使用 encodeHeader()
Posted
技术标签:
【中文标题】PHP Mail_Mime:如何在电子邮件正文中正确使用 encodeHeader()【英文标题】:PHP Mail_Mime: How to properly use encodeHeader() on the body of an email 【发布时间】:2014-06-05 16:46:55 【问题描述】:我该如何解决这个问题的字符编码:
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】:在调用 $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
【讨论】:
以上是关于PHP Mail_Mime:如何在电子邮件正文中正确使用 encodeHeader()的主要内容,如果未能解决你的问题,请参考以下文章
带有附件的梨邮件在 $mime = new Mail_mime 处失败