PHPMailer 每 75 个字符插入一个等号
PHPMailer inserts '=' equal sign every 75th character
使用 PHPMailer 5.2.14,电子邮件在 text/html 中发送。传出的文本每隔 75 个字符就会散布一些等号。
我尝试使用 EOL workaround,但它没有删除多余的等号:
$email = new PHPMailer();
$email->From = 'from@example.com';
$email->FromName = 'FromUser';
$email->AddAddress( 'to@example.com' );
$email->Subject = 'This is a test';
$email->IsHTML(true);
$email->Body = "<p>This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. </p>";
// fix EOL here?
$email->LE = PHP_EOL;
$email->Send();
收到后的结果来源:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><font face="arial"><base href="http://example.com/"><!-- </base> -->=
<p>This is a test. This is a test. This is a test. This i=
s a test. This is a test. This is a test. This is a test.=
This is a test. This is a test. This is a test. Th=
is is a test. This is a test. This is a test. This is a t=
est. This is a test. This is a test. This is a test. =
</p></font>
在 Outlook 中查看时出现等号。当我将相同的 text/html 发送到 gmail 帐户时,等号不存在。
需要做什么来消除使用 Outlook 的收件人的这些杂散等号?
您的文档应如下所示:
<!DOCTYPE html>
<head>
meta stuff and <base href...>
</head>
<body>
HTML stuff
</body>
</html>
任何不符合 HTML 的内容都会影响您的一天。
据我所知,您有属于 <head>
的元数据和属于 <body>
的 <font>
标签等等。如果没有合适的 HTML 文档结构化,那么肯定会有一些抱怨。包括有效的文档类型。
关于 <font>
标签的快速旁注;它已弃用。
您可以改用内联 CSS 样式。不要使用 <style>
标签,因为大多数电子邮件客户端会丢弃并忽略它。
这称为 quoted-printable encoding,在电子邮件中很常见。等号用作转义字符,行长度限制为 76 个字符。如果 Outlook 无法识别这一点,您可能需要手动设置 headers 告诉它它是以这种方式编码的。
我在 PHPMailer 中遇到了与 html-emails 相同的问题。我测试了不同的东西并发现:
- 如果邮件有特殊长度,就会出现问题 - 在我的例子中,一行超过 1002 个字母(当我删除了一些字母(与哪些字母无关)时,电子邮件是正确的)
- 该问题仅在某些 email-programms 中可见(例如 MS Outlook、网站 t-online.de;yahoo 没有问题)
- 我已经测试了 PHPMailer 5.2.7 - 5.2.14:PHPMailer >5.2.10 中存在问题(PHPMailer 5.2.7 - 5.2.10 中没有问题)
- 类似“$mail->Encoding = "7bit";”的解决方案或 '$mail->LE = PHP_EOL;'对我没用
- 通过 isSmtp() 发送电子邮件时没有问题。
- 在两个不同的服务器上测试:服务器 1 包含等号,服务器 2 不包含该符号但有错误的换行符 - 两个服务器上的 php-configuration 几乎相同 > 它似乎不是一个 php-problem
所以对我来说,解决方案是 "take PHPMailer 5.2.10",直到他们在更新版本中解决了这个问题 - 没有好的解决方案,但它对我有用,直到我找到更好的解决方案 ;-)
$email = new PHPMailer();
$email->From = 'from@example.com';
$email->FromName = 'FromUser';
$email->AddAddress( 'to@example.com' );
$email->Subject = 'This is a test';
$email->IsHTML(true);
$email->Body = "<p>This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.&`enter code here`nbsp; This is a test. This is a test. This is a test. </p>";
// fix EOL here?
$email->LE = PHP_EOL;
$email->Send();
使用 '$mail->Encoding = 'base64';
它现在适用于 v5.2.17。
希望这最终在 v6 中得到修复。
使用 PHPMailer 5.2.14,电子邮件在 text/html 中发送。传出的文本每隔 75 个字符就会散布一些等号。
我尝试使用 EOL workaround,但它没有删除多余的等号:
$email = new PHPMailer();
$email->From = 'from@example.com';
$email->FromName = 'FromUser';
$email->AddAddress( 'to@example.com' );
$email->Subject = 'This is a test';
$email->IsHTML(true);
$email->Body = "<p>This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. </p>";
// fix EOL here?
$email->LE = PHP_EOL;
$email->Send();
收到后的结果来源:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><font face="arial"><base href="http://example.com/"><!-- </base> -->=
<p>This is a test. This is a test. This is a test. This i=
s a test. This is a test. This is a test. This is a test.=
This is a test. This is a test. This is a test. Th=
is is a test. This is a test. This is a test. This is a t=
est. This is a test. This is a test. This is a test. =
</p></font>
在 Outlook 中查看时出现等号。当我将相同的 text/html 发送到 gmail 帐户时,等号不存在。
需要做什么来消除使用 Outlook 的收件人的这些杂散等号?
您的文档应如下所示:
<!DOCTYPE html>
<head>
meta stuff and <base href...>
</head>
<body>
HTML stuff
</body>
</html>
任何不符合 HTML 的内容都会影响您的一天。
据我所知,您有属于 <head>
的元数据和属于 <body>
的 <font>
标签等等。如果没有合适的 HTML 文档结构化,那么肯定会有一些抱怨。包括有效的文档类型。
关于 <font>
标签的快速旁注;它已弃用。
您可以改用内联 CSS 样式。不要使用 <style>
标签,因为大多数电子邮件客户端会丢弃并忽略它。
这称为 quoted-printable encoding,在电子邮件中很常见。等号用作转义字符,行长度限制为 76 个字符。如果 Outlook 无法识别这一点,您可能需要手动设置 headers 告诉它它是以这种方式编码的。
我在 PHPMailer 中遇到了与 html-emails 相同的问题。我测试了不同的东西并发现:
- 如果邮件有特殊长度,就会出现问题 - 在我的例子中,一行超过 1002 个字母(当我删除了一些字母(与哪些字母无关)时,电子邮件是正确的)
- 该问题仅在某些 email-programms 中可见(例如 MS Outlook、网站 t-online.de;yahoo 没有问题)
- 我已经测试了 PHPMailer 5.2.7 - 5.2.14:PHPMailer >5.2.10 中存在问题(PHPMailer 5.2.7 - 5.2.10 中没有问题)
- 类似“$mail->Encoding = "7bit";”的解决方案或 '$mail->LE = PHP_EOL;'对我没用
- 通过 isSmtp() 发送电子邮件时没有问题。
- 在两个不同的服务器上测试:服务器 1 包含等号,服务器 2 不包含该符号但有错误的换行符 - 两个服务器上的 php-configuration 几乎相同 > 它似乎不是一个 php-problem
所以对我来说,解决方案是 "take PHPMailer 5.2.10",直到他们在更新版本中解决了这个问题 - 没有好的解决方案,但它对我有用,直到我找到更好的解决方案 ;-)
$email = new PHPMailer();
$email->From = 'from@example.com';
$email->FromName = 'FromUser';
$email->AddAddress( 'to@example.com' );
$email->Subject = 'This is a test';
$email->IsHTML(true);
$email->Body = "<p>This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.&`enter code here`nbsp; This is a test. This is a test. This is a test. </p>";
// fix EOL here?
$email->LE = PHP_EOL;
$email->Send();
使用 '$mail->Encoding = 'base64';
它现在适用于 v5.2.17。
希望这最终在 v6 中得到修复。