【问题标题】:PHP - Plain text emailPHP - 纯文本电子邮件
【发布时间】:2012-02-01 11:40:08
【问题描述】:

如何把它变成纯文本邮件?

 $bound_text=md5(uniqid(time()));
    $headers.="MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed; boundary=\"PHP-mixed-$bound_text\"\r\n";

    $message="--PHP-mixed-$bound_text\r\n"      
                ."Content-Type: text/html; charset=\"utf-8\"\r\n"
                ."Content-Transfer-Encoding: 7bit\r\n\r\n"  
                ."<html><head></head><body>"
                ."<div style=\"font-family: Arial, Helvetica, sans-serif; font-size : 1.3em; color: #000000;width: 100%;text-align: left;\">$text_message</div></body></html>\r\n\r\n"  
                ."--PHP-mixed-$bound_text\r\n"  
                ."Content-Transfer-Encoding: base64\r\n"
                ."Content-Disposition: attachment; filename=\"$attachment\"\r\n"
    ."Content-Type: image/jpeg; name=\"$attachment\"\r\n\r\n"
     .chunk_split($file)
            ."\r\n\r\n"
                ."--PHP-mixed-$bound_text--\r\n\r\n";

    }

是否只是删除 HTML 部分并将 text/html 更改为 text/plain

【问题讨论】:

  • 可能。但是您是否考虑过使用 PHPMailer or Swiftmailer 来不必对此类事情进行微观管理?
  • 现在我需要使用发布的代码,但感谢您的建议。
  • 如果您确定$text_message 本身不包含 HTML 标记,那么您可能是安全的。否则,您可能需要对该变量进行一些整理(例如'&lt;br /&gt;' -> "\n",strip_tags)

标签: php email plaintext


【解决方案1】:

删除 HTML 应该可以解决问题,但您可能还想将内容类型更改为 text/plain:

."Content-Type: text/plain; charset=\"utf-8\"\r\n"

(我本来可以发表评论的,但我还不能发布 cmets :))

【讨论】:

    猜你喜欢
    • 2014-06-05
    • 2012-07-13
    • 1970-01-01
    • 2017-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    相关资源
    最近更新 更多