3

我正在尝试使用 php 的mail()功能发送 HMTL 电子邮件,并注意到电子邮件中的某些内容已损坏。我从 gmail 中阅读原文发现,邮件正文中的行长度都相同,这会在不方便的地方削减 HTML 标签。

我的标题是多部分的,在 html 和 plain 之间有 7 位的边界。我发送的一个例子是:

<a href="site.com/unsub">Unsubscribe</a>

但是由于它的位置,消息将它拆分为

<a href="site.co
m/ubsub">unsubscribe</a>

这打破了超链接。有什么我错过或没有得到的吗?我已经看到过使用像 swiftmailer 这样的邮件库——我可以使用它——但我想真正理解这种行为。

编辑:

如何mail()称呼:

$headers = 'From: Me <me@site.com>' . "\r\n" . 'MIME-Version: 1.0'
$headers .= "\r\n" . "Content-Type: multipart/mixed; charset=ISO-8859-1; boundary=$boundary"
$subject = 'subject';
$html_message = '--' . $boundary . "\r\n";
$html_message .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$html_message .= 'Content-Transfer-Encoding: 7bit' . "\r\n" . "\r\n";
$html_message .= $message . "\r\n";
// plaintext added similarly, with different content-type. Omitted.
mail($to,$subject,$html_message, $headers);

编辑#2:

展开$message.

$message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" /><title>"
$message .= "Page Title</title></head><body style=\"margin: 0; padding: 0; font-family: open \'Open Sans\', \'Open Sans Bold\';\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" ><tr><td><table align=\"center\"  bgcolor=\"#FFFFFF\" border=\"0\"cellpadding=\"0\" cellspacing=\"0\" width=\"600\"><tr><td align=\"right\" style=\"padding: 20px 20px 20px 20px;\"> <font color=\"#EA5D0F\">[</font> <a href=\"http://SITE.com\" style=\"color:#000001; text-decoration: none !important;\">Sign In </a><font color=\"#EA5D0F\">][</font> <a href=\"http://about.SITE.com\" style=\"color:#000001; text-decoration: none !important;\">About </a><font color=\"#EA5D0F\">][</font> <a href=\"http:/SITE.com/search\" style=\"color:#000001; text-decoration: none !important;\">Search</a><font color=\"#EA5D0F\">]</font></td></tr><tr><td bgcolor=\"#FFFFFF\" align=\"center\" style=\"padding: 40px 0px 0px 0px;\"><img src=\"http://about.SITE.com/wp-content/uploads/2013/08/SITE.plain_.png\" alt=\"SITE Logo\" width=\"300\" style=\"display: block;\" /></td></tr><tr><td style=\"padding: 10px 20px 20px 20px;\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" ><tr><td bgcolor=\"#FFFFFF\" style=\"padding: 30px 10px 10px 10px; text-align:center; font-size: 1.2em; font-weight:bold;\"> <hr color=\"#EA5D0F\"/>"

这种情况持续了相当长的一段时间。不确定要包括多少。

4

1 回答 1

0

我过去确实有这个问题。虽然我不知道原因是什么,但通过替换 every 解决了>>\r\n

$message = str_replace(">", ">\r\n", $message);
于 2013-11-03T21:21:38.147 回答