【问题标题】:HTML Email stripping out charactersHTML 电子邮件去除字符
【发布时间】:2012-07-26 22:10:18
【问题描述】:

我目前有一封通过 PHP 发送的 HTML 电子邮件。样式和一切都很好,问题是它正在从我包含在电子邮件中的文本中删除一些字符。

这是我的标题

$from = "noreply@myemail.com";
$headers .= "MIME-Version: 1.0\r\n";
$headers  = "From: ".$from."\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

有人有什么想法吗?提前致谢

这是完整的代码。有时它的空格,或者它会在单词中间添加一个空格。其他时候它会漏掉一个单词中的字符

$from = "noreply@mydomain.co.uk";
$headers .= "MIME-Version: 1.0\r\n";
 $headers  .= "From: ".$from."\r\n"; 
 $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <!-- Facebook sharing information tags --></head><body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" style="-webkit-text-size-adjust: none;margin: 0;padding: 0;background-color: #000000;width: 100%;"><center><table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="backgroundTable" style="margin: 0;padding: 0;background-color: #000000;height: 100%;width: 100%;"><tr><td align="center" valign="top" style="border-collapse: collapse;"><table border="0" cellpadding="0" cellspacing="0" width="600" id="templateContainer" style="border: 1px solid #000000;background-color: #000000;"><tr><td align="center" valign="top" style="border-collapse: collapse;"><table border="0" cellpadding="0" cellspacing="0" width="600" id="templateHeader" style="background-color: #FFFFFF;border-bottom: 0;"> <tr> <td class="headerContent" style="border-collapse: collapse;color: #202020;font-family: georgia;font-size: 34px;font-weight: bold;line-height: 100%;padding: 0;text-align: center;vertical-align: middle;"><a target="_blank" name="sw" href="http://www.mydomain.co.uk" href="" title=""><img src="http://www.mydomain.co.uk/wp-content/uploads/2012/07/header.jpg" style="max-width: 600px;border: 0;height: auto;line-height: 100%;outline: none;text-decoration: none;" id="headerImage campaign-icon" mc:label="header_image" mc:edit="header_image" mc:allowdesigner mc:allowtext></a></td></tr></table></td></tr> <tr><td align="center" valign="top" style="border-collapse: collapse;"><table border="0" cellpadding="0" cellspacing="0" width="600" id="templateBody"><tr> <td valign="top" class="bodyContent" style="border-collapse: collapse;background-color: #000000;"> <!-- // Begin Module: Standard Content \ --> <table border="0" cellpadding="20" cellspacing="0" width="100%"> <tr> <td valign="top" style="border-collapse: collapse;"> <div mc:edit="std_content00" style="color: #AC9366;font-family: georgia;font-size: 14px;line-height: 150%;text-align: left;"> <h3 class="h3" style="color: #C0B391;display: block;font-family: georgia;font-size: 16px;font-weight: bold;line-height: 100%;margin-top: 0;margin-right: 0;margin-bottom: 10px;margin-left: 0;text-align: left;">Hi Aaron,</h3> <strong>Thanks for registering with us.</strong><br><p style="font-style:italic;">At Wicked, we believe you can get lots of pleasure by sharing. So we\'ll be sharing the details of our launch with you, plus some wonderfully wicked behind the scenes coverage of our photography shoot, featuring our luxury lingerie collection designed exclusively by <a href="http://www.mydomain.co.uk/interviews/wicked/" target="_blank" name="leanna" style="color: #C0B391;font-weight: normal;text-decoration: underline;">Leanne Brooke</a>.<br><br> We\'ll also give you the chance to win invitations to our VIP launches (in London &amp; Leeds), as well as having one of the first ever SW lingerie pieces, made to measure for you, by Leanne. <br><br> Until then... <br><br> SW.</p><br><br><br><br> <a href="http://www.twitter.com/wearewicked" target="_blank" name="swtwitter" style="color: #C0B391;font-weight: normal;text-decoration: underline;"><img src="http://www.mydomain.co.uk/wp-content/uploads/2012/07/t-email.jpg" alt="" style="border: 0;height: auto;line-height: 100%;outline: none;text-decoration: none;display: inline;"></a> &nbsp; <a href="https://www.facebook.com/mypage" target="_blank" name="swfacebook" style="color: #C0B391;font-weight: normal;text-decoration: underline;"><img src="http://www.mydomain.co.uk/wp-content/uploads/2012/07/f-email.jpg" alt="" style="border: 0;height: auto;line-height: 100%;outline: none;text-decoration: none;display: inline;"></a>  &nbsp; <a href="http://www.mydomain.co.uk" target="_blank" name="swsite" style="color: #C0B391;font-weight: normal;text-decoration: underline;"><img src="http://www.mydomain.co.uk/wp-content/uploads/2012/07/sw-email.png" alt="" style="border: 0;height: auto;line-height: 100%;outline: none;text-decoration: none;display: inline;"></a>  &nbsp; <a href="http://www.mydomain.co.uk/blog" target="_blank" name="swblog" style="color: #C0B391;font-weight: normal;text-decoration: underline;"><img src="http://www.mydomain.co.uk/wp-content/uploads/2012/07/blog.png" alt="" style="border: 0;height: auto;line-height: 100%;outline: none;text-decoration: none;display: inline;"></a></h3></div></td> </tr> </table></td> </tr> </table></td></tr><tr><td align="center" valign="bottom" style="border-collapse: collapse;"><table border="0" cellpadding="0" cellspacing="0" width="600"> <tr> <td style="border-collapse: collapse;"><img src="http://www.mydomain.co.uk/wp-content/uploads/2012/07/footer.jpg" style="max-width: 600px;border: 0;height: auto;line-height: 100%;outline: none;text-decoration: none;" id="headerImage campaign-icon" mc:label="header_image" mc:edit="header_image" mc:allowdesigner mc:allowtext> </td> </tr> </table> <!-- // End Template Footer \ --> </td> </tr> </table> <br> </td> </tr> </table> </center> </body></html>';

 mail($email, 'My Subject line', $body, $headers);

(请参阅pastebin 以便于阅读)

【问题讨论】:

  • 你能发布更多关于“剥离一些字符”部分的细节吗?
  • 缺少哪些字符?你在哪里设置内容?
  • 它包含在电子邮件中的文本,有时它会删除一个字符或空格,这因电子邮件而异。
  • 删除了哪些字符?你能展示一些有问题的代码吗?
  • 好的,然后提供一些将设置内容的代码。

标签: html email


【解决方案1】:

如果您的内容的行数超过 1000 个字符,大多数邮件服务器会强制重新格式化。使用带引号的可打印或 base64 编码包装您的内容,或者只需在每 75 个字符左右的空白字符上插入换行符。

也同意 ISO 8859-1 在这里似乎可疑的评论,尽管它似乎不会影响此特定消息。但是在这个时代,您编写的任何代码都应该使用 UTF-8。

【讨论】:

    猜你喜欢
    • 2012-09-11
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    • 2010-12-20
    • 2011-02-27
    • 2011-04-15
    相关资源
    最近更新 更多