【问题标题】:PHPMailer inserts '=' equal sign every 75th characterPHPMailer 每 75 个字符插入 '=' 等号
【发布时间】:2023-03-04 16:42:02
【问题描述】:

使用 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.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; </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.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This i=
s a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.=
&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; Th=
is is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a t=
est.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp;=
 </p></font>

在 Outlook 中查看时会出现等号。当我将相同的文本/html 发送到 gmail 帐户时,等号不存在。

需要采取什么措施来消除使用 Outlook 的收件人的这些杂散等号?

【问题讨论】:

  • 请缩小你的文字大小,我们不需要那么多行就可以理解有=。您使用什么代码对文本进行编码?
  • 如果这里不适合询问 php 问题,请建议一个合适的 sub。
  • 再次对于投票关闭此问题作为离题的个人,请建议适当的子而不是默默地杀死问题。我还建议不要关闭它,因为截至本回复,标签 PHPMailer 已被使用 ''2055'' 次。
  • 甚至可能是本地问题和 Outlook 中的某些设置。据我所见,你有属于 的元数据和属于 的 等等。如果没有正确的 HTML 文档结构,那么肯定会抱怨。包括一个有效的文档类型。
  • @Fred-ii-,添加 html 和 body 标签有效。如果您将此添加为答案,我会适当地感谢您。

标签: php phpmailer


【解决方案1】:

我在 PHPMailer 中遇到了同样的问题。我测试了不同的东西并发现:

  • 如果邮件具有特殊长度,则会出现问题 - 在我的情况下,一行中 > 1002 个字母(当我删除了一些字母(与哪些字母无关)时,电子邮件是正确的)
  • 该问题仅在某些电子邮件程序中可见(例如 MS Outlook、网站 t-online.de;雅虎没有问题)
  • 我测试了 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 配置几乎相同 > 似乎不是 php 问题

所以对我来说,解决方案是“使用 PHPMailer 5.2.10”,直到他们在新版本中解决问题 - 没有好的解决方案,但它对我有用,直到我找到更好的解决方案 ;-)

【讨论】:

  • 5.2.10 解决了这个问题。感谢您的回答。
【解决方案2】:

您的文档应如下所示:

<!DOCTYPE html>
<head>
   meta stuff and <base href...>
</head>
    <body>
    HTML stuff
    </body>
</html>

任何超出此范围且不符合 HTML 的内容都会影响您的工作。

据我所知,您有属于 &lt;head&gt; 的元数据和属于 &lt;body&gt; 等的 &lt;font&gt; 标签等。如果没有正确的 HTML 文档结构,那么肯定会抱怨.包括一个有效的文档类型。

关于&lt;font&gt; 标签的快速旁注;它已被弃用。

您可以改用内联 CSS 样式。不要使用&lt;style&gt; 标签,因为大多数电子邮件客户端会丢弃它并忽略它。

【讨论】:

  • 我不知道为什么这被选为正确答案。虽然这是个好建议,但与问题无关。
  • @Synchro Read OP's comment...。它与它有关。一定要看看他们的代码和他们试图发送的消息。
  • Fred 的答案是可靠的,但 SusiMage 的答案(昨天发布)现在被标记为选定的答案。请参阅他/她的帖子了解原因。
  • @acoder 很高兴看到你有你的解决方案,干杯 - 我投了赞成票。
【解决方案3】:

这被称为quoted-printable encoding,在电子邮件中很常见。等号用作转义字符,行长限制为 76 个字符。如果 Outlook 无法识别这一点,您可能必须手动设置标头,告诉它它是以这种方式编码的。

【讨论】:

    【解决方案4】:

    '$mail-&gt;Encoding = 'base64'; 现在适用于我们 v5.2.17。 希望这最终在 v6 中得到修复。

    【讨论】:

      【解决方案5】:

      通过添加 $email->crlf = "\r\n"; 你可以解决这个问题。

      【讨论】:

        【解决方案6】:

        我正在使用 phpMailer 5.2.25 并通过 SendPulse 网关发送。通过我的 ISP 直接使用 SMTP 没有问题,但是在一行的 75 个字符之后看到了“=”符号 - 所以它与行长度换行有关。设置 $mail->Encoding = 'base64';根据 asdfklgash 的回答,防止插入等号(通过 A/B 比较证明)。

        【讨论】:

          【解决方案7】:
          $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.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&`enter code here`nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; </p>";
          
          // fix EOL here? 
          $email->LE = PHP_EOL;
          
          $email->Send();
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2020-01-31
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-04-09
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多