html格式邮件垃圾率过高的处理办法
原先的邮件采用Content-Type: text/html
下面是X-Spam的得分情况,当 score 超过6分就被当作垃圾邮件处理了
X-Spam-Status: Yes, score=6.3 required=6.0 tests=CONTENT_TYPE_PRESENT, DIRECTUNKNOWN,HTML_MESSAGE,MIME_HTML_ONLY,ONLY1HOPDIRECT,RDNS_NONE, TO_NO_BRKTS_FROM_MSSP,TO_NO_BRKTS_NORDNS_HTML,URIBL_BLOCKED,UTF8 autolearn=no version=3.3.1 X-Spam-Report: * 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. * See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block * for more information. * [URIs: handbook.jp] * -0.1 CONTENT_TYPE_PRESENT exists:Content-Type * 0.3 DIRECTUNKNOWN directly received spam from suspicious dynamic IP * 1.0 ONLY1HOPDIRECT ONLY1HOPDIRECT * 1.0 HTML_MESSAGE BODY: HTML included in message * 0.4 MIME_HTML_ONLY BODY: Message only has text/html MIME parts * -0.1 UTF8 RAW: UTF-8 message body * 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS * 2.5 TO_NO_BRKTS_FROM_MSSP Multiple formatting errors * 0.0 TO_NO_BRKTS_NORDNS_HTML To: misformatted and no rDNS and HTML only
解决办法就是采用Content-Type: multipart/alternative
这种类型可以同时发送两种类型的邮件 text/plain 和 text/html, 大大降低邮件的 score
下面是采用multipart/alternative 这种类型的得分情况 因为低于6分 没有X-Spam-Report
X-Spam-Status: No, score=3.5 required=6.0 tests=CONTENT_TYPE_PRESENT, DIRECTUNKNOWN,HTML_MESSAGE,MULTIPART_ALTERNATIVE,ONLY1HOPDIRECT,RDNS_NONE, URIBL_BLOCKED,UTF8 autolearn=no version=3.3.1
下面是具体代码
function sendAlternativeMail($to, $from, $subject, $plainmessage, $htmlmessage, $bcc = null, $cc = null) { $to = base64($to); $from = base64($from); $subject = ‘=?UTF-8?B?‘ . base64_encode($subject) . ‘?=‘; $boundary = uniqid(‘np‘);
//set header $headers = "MIME-Version: 1.0\r\n"; $headers .= "From: ".$from."\r\n"; $cc && $headers .= "Cc: $cc\n"; $bcc && $headers .= "Bcc: $bcc\n"; $headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n"; //set plain body $message = "\r\n\r\n--" . $boundary . "\r\n"; $message .= "Content-type: text/plain;charset=utf-8\r\n\r\n"; $message .= $plainmessage; //set html body $message .= "\r\n\r\n--" . $boundary . "\r\n"; $message .= "Content-type: text/html;charset=utf-8\r\n\r\n"; $message .= $htmlmessage; //end $message .= "\r\n\r\n--" . $boundary . "--"; return mail($to, $subject, $message, $headers); }
//encode email address function base64($string){ if (!$string) { return null; } $array = explode(‘,‘, $string); foreach ($array as &$a) { $a = trim($a); if (preg_match(‘/(.*)(<[^>]+@[^>]+>)$/U‘, $a, $match)) { $a = ‘=?UTF-8?B?‘ . base64_encode($match[1]) . ‘?=‘ . $match[2]; } } return implode(‘,‘, $array); }
参考资料:http://krijnhoetmer.nl/stuff/php/html-plain-text-mail/
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。