【问题标题】:exclamation mark is appears in email message body using phpmailer感叹号出现在使用 phpmailer 的电子邮件正文中
【发布时间】:2012-10-02 03:44:49
【问题描述】:

我正在使用 phpmailer 在我的网站上发送电子邮件。我的代码工作正常,但有时在电子邮件正文中随机包含感叹号。我的代码如下:

$mail->SetFrom(FROM_EMAIL,FROM_NAME); //emailid of sender(admin)                
$mail->Subject = 'Subject here.'; //subject of email
$mail->AddAddress(Address here); //emailid of user(recipient)
$content = 'some html code here';

$mail->MsgHTML($content); //this is body of email
$mail->Send();

这很好用。但是找不到为什么有时会出现感叹号。 提前谢谢...

【问题讨论】:

  • 感叹号!或问号???通常,如果查看 HTML 邮件的客户端误解了字符集(因为您的邮件误报了它),无效字符将显示为 ?
  • 可能需要$mail->CharSet = 'UTF-8';

标签: php phpmailer


【解决方案1】:

如果您使用的是 PHPmailer,那么只需一行代码即可:

$mail = new PHPMailer();
$mail->Encoding = 'base64';

这将在内部执行 Content-Transfer-Encoding: base64 和 chunk_split(base64_encode($message))。

【讨论】:

    【解决方案2】:

    我也有这个问题,经过长时间的搜索,我发现你应该把你的 HTML 换行

    $emailContent = '<p>some large html</p>';
    $mail->msgHTML(wordwrap($emailContent, 50));
    

    【讨论】:

      【解决方案3】:

      我知道这已经晚了,但有一个替代解决方案对我有用:

      使用此行使用 base64 对整个消息进行编码:

      $message = chunk_split(base64_encode($message));
      

      然后,将其附加到您的标题中:

      $headers .= "Content-Transfer-Encoding: base64\r\n\r\n";
      

      这将告诉邮件客户端您的邮件是 base64 编码的。

      【讨论】:

        【解决方案4】:

        我认为这是因为电子邮件的一行不能超过 998 个字符。

        尝试添加,

        $mail->WordWrap = 50;
        

        【讨论】:

        • 看看这个,tinyfrogsoftware.com/…希望对你有帮助。
        • 或者尝试在$content = 'some html code here';之后添加$content = wordwrap($content, 50);
        • 您能解释一下为什么会出现这种情况,或者参考一下为什么它不能处理超过 998 个字符吗?
        • @StefanDunn 998 个字符的限制是由于发送、接收或存储 Internet 消息格式消息的许多实现中的限制,这些消息根本无法处理一行超过 998 个字符。更多详情RFC 2822
        • Tinyfrogsoftware 链接已失效。这是一个实时存档版本 - web.archive.org/web/20100424013747/http://…
        猜你喜欢
        • 2011-12-16
        • 1970-01-01
        • 1970-01-01
        • 2018-04-25
        • 2019-01-03
        • 2012-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多