PHP mail() 多部分/替代 HTML 和纯文本电子邮件

标签 php email 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 电子邮件时,他们才会被抓到。任何帮助,将不胜感激。是否可以向 header 添加更多内容以帮助防止垃圾邮件过滤器?

最佳答案

许多垃圾邮件过滤器使用累积评分系统来确定传入邮件是否为垃圾邮件。个别“垃圾邮件”问题可能会顺利通过,但如果在特定电子邮件中出现多个问题,则达到阈值并转储邮件。

在您的消息中,我看到了一些可能会增加您分数的事情:

Subject: "Get Your Offers Here"

Solution: Try including specific text about the contents of your email and consider including your company name

From: "Test Email: testemail@testemail.com";

Solution: Use a real email address. Also, make sure the server you are sending email from is configured properly (see SPF)

Content: Unknown

Solution: Make sure your content is specific and relevant. Make sure any links point to the domain from which the email originated. Avoid using too many "spammy" keywords ("offer," "free," "l@@k", etc.).

您可以对自己的电子邮件进行气味测试。删除对您的公司和产品的所有引用并输入通用术语。考虑一下结果,看看如果邮件到达您的邮箱,您是否会删除它。

关于PHP mail() 多部分/替代 HTML 和纯文本电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6511567/

相关文章:

php - 从PHP到MySQL的DateTime

c# - 构建解决方案以支持在 Linux 环境中发送邮件通知

php - 使用 PHP mail() 发送多部分/替代

ruby-on-rails-3 - 我的 Gmail 收件箱中的 noname 附件

php - 为什么带有 PCRE_UTF8 的 PHP preg_match_all 在 CLI 上和通过 Apache/mod_php 给出不同的结果?

javascript - 如何将变量和数据从PHP传递到JavaScript?

php - 如何显示 cron 作业的计时器

python - 使用 EmailMultiAlternatives 向 django 发送电子邮件

java - 解释套接字响应的好方法

php - 使用 Swift Mailer 发送多部分/替代邮件