【发布时间】: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 标记,那么您可能是安全的。否则,您可能需要对该变量进行一些整理(例如'<br />'->"\n",strip_tags)