为了避免Postfix在smtp_line_length_limit
之后包裹超长行(通常是998个字符),我目前正在使用php's tidy library在HTML电子邮件中包装长行(请参阅related question):< / p>
$oTidy = new tidy();
$message = $oTidy->repairString($message,
array("show-errors" => 0, "show-warnings" => false, "force-output" => true,
"alt-text" => "Please display images", "bare" => true, "doctype" => "auto",
"drop-empty-paras" => false, "fix-bad-comments" => false, "fix-uri" => true,
"join-styles" => false, "merge-divs" => true, "merge-spans" => true,
"preserve-entities" => true, "wrap" => 68),
"utf8"
);
在保持HTML和CSS有效方面,Tidy非常擅长包装长行 不幸的是,它更像是尝试修复无效的HTML标记,更改HTML标记,文档类型等。
我只需要换行 - 其他整洁的东西是开销,有时比其他任何东西都烦人。
现在我尝试使用PHPMailer的wrapText()
功能。不幸的是,我发现了bug,这对我来说毫无用处
PHPMailer转换此源代码
<html>
<body>
Loremipsumdolorsitametconsetetursadipscing<span style="font-family:'Courier New',sans-serif">lorem</span>
</body>
</html>
到
<html>
<body>
Loremipsumdolorsitametconsete<span style="font-family:'Courier
New',sans-serif">lorem</span>
</body>
</html>
打破某些客户端中lorem一词的字体格式(Courier New)。
现在我的问题:
如何在不破坏HTML和CSS的情况下安全地包装HTML行?
Tidy如何做到这一点?我应该使用DOM解析器吗?是否有PHP版本的Tidy源代码(我还没有找到)?
答案 0 :(得分:2)
最好的方法似乎是quoted-printable
编码,因为它可以将行分成小块字符,同时保留内容过滤器的可读性,而不会有破坏任何格式的风险。
Base64
也是一种选择,但会增加垃圾邮件分类的风险。
这两个选项都会增加源代码的长度(quoted-printable
,尤其是对于非ascii字符)。
旁注:
如上所述,PHPMailer的wrapText()
will not be fixed可以通过邮件编码解决。
答案 1 :(得分:1)
base64_encode()
chunk_split()