PHP mail()Multipart / Alternative for HTML&纯文本电子邮件

时间:2011-06-28 18:47:27

标签: php email multipart-alternative

我使用以下代码发送Multipart / Alternative HTML和纯文本电子邮件。这些电子邮件正在发送精美内容,但其中一些邮件被垃圾邮件过滤器捕获。这是我正在使用的代码。

$notice_text = "This is a multi-part message in MIME format.";
$plain_text = "Some Plain Text Here\n\n";
$html_text = '<html><head><title>Sample HTML Email</title></head><body>';
$html_text .= '<p>Some text will go here.</p>';
$html_text .= '<p><img src="http://www.mydomain.com/img/offers.jpg" /></p>';
$html_text .= '<p>Can\'t see the images? <a href="http://www.mydomain.com/print_offer.php?promo=' . $promo_code . '">Click here</a></p>';
$html_text .= '</body></html>';

$semi_rand = md5(time());
$mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";
$mime_boundary_header = chr(34) . $mime_boundary . chr(34);

$from = "Test Email <testemail@testemail.com>";
$subject = "Get Your Offers Here";

$body = "$notice_text

--$mime_boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

$plain_text

--$mime_boundary
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

$html_text

--$mime_boundary--";

mail($email, $subject, $body,
    "From: " . $from . "\n" .
    "bcc: " . $bcc . "\n" .
    "MIME-Version: 1.0\n" .
    "Content-Type: multipart/alternative;\n" .
    "     boundary=" . $mime_boundary_header);

是什么导致它进入垃圾邮件过滤器?当我以纯文本形式发送电子邮件时,它们通过就好了,只有当我发送HTML电子邮件时才会发现它们被抓住了。任何帮助,将不胜感激。我是否可以添加更多标题以帮助防止垃圾邮件过滤?

2 个答案:

答案 0 :(得分:5)

许多垃圾邮件过滤器使用累积评分系统来确定传入邮件是否为垃圾邮件。单个“垃圾邮件”问题可能会滑过,但如果某个电子邮件中存在多个问题,则会达到阈值并丢弃邮件。

在你的留言中,我看到一些可能会提高你得分的事情:

  

主题“在此处获取您的优惠”

     

解决方案:尝试提供有关电子邮件内容的特定文字,并考虑包含您的公司名称

  

发件人:“测试电子邮件:testemail@testemail.com”;

     

解决方案:使用真实的电子邮件地址。此外,请确保正在配置发送电子邮件的服务器(请参阅SPF

  

内容: 未知

     

解决方案:确保您的内容具体且相关。确保所有链接指向发送电子邮件的域。   避免使用太多“垃圾”关键字(“报价”,“免费”,“l @@ k”,   等)。

您可以在自己的电子邮件上进行嗅觉测试。删除对贵公司和产品的所有引用,并输入通用术语。考虑结果,看看是否会在邮件到达邮箱时删除邮件。

答案 1 :(得分:2)

您的图片文件的直接链接在spamdar上也非常高。