-1

我正在使用代码发送带有附件的电子邮件,电子邮件发送但事情是它作为垃圾邮件发送。有人能猜出原因吗?这是我的代码:

$to =    'krishna25@gmail.com';
$subject =   'PHP Mail Attachment Test';
$bound_text =   "jimmyP123";
$bound =    "--".$bound_text."\r\n";
$bound_last =   "--".$bound_text."--\r\n";

$headers =  "From: admin@server.com\r\n";
$headers .= "MIME-Version: 1.0\r\n"
    ."Content-Type: multipart/mixed; boundary=\"$bound_text\"";

$message .= "If you can see this MIME than your client doesn't accept MIME types!\r\n"
    .$bound;

$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
    ."Content-Transfer-Encoding: 7bit\r\n\r\n"
    ."hey my <b>good</b> friend here is a picture of regal beagle\r\n"
    .$bound;

$file = file_get_contents("http://reality.com/images/ezlogo.png");

$message .= "Content-Type: image/png; name=\"http://reality.com/images/ezlogo.png\"\r\n"
    ."Content-Transfer-Encoding: base64\r\n"
    ."Content-disposition: attachment; file=\"http://reality.com/images/ezlogo.png\"\r\n"
    ."\r\n"
    .chunk_split(base64_encode($file))
    .$bound_last;
if(mail($to, $subject, $message, $headers)) 
{
     echo 'MAIL SENT'; 
} else { 
     echo 'MAIL FAILED';
}
4

2 回答 2

1

在您的代码中,您显示了“发件人”地址,如下所示:

$headers =  "From: admin@server.com\r\n";

确保这是您使用的有效地址。

此外,您可以尝试设置其他标题,例如Return-PathReply-To

$header .= "Reply-To: Admin <admin@server.com>\r\n"; 
$header .= "Return-Path: Admin <admin@server.com>\r\n";

来源 - http://www.transio.com/content/how-pass-spam-filters-php-mail

希望这可以帮助!

于 2013-08-05T11:00:33.810 回答
1

垃圾邮件过滤器的一大标志是发送没有格式良好的 html 正文的 html 内容。

IE。你有一个部分

$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
."hey my <b>good</b> friend here is a picture of regal beagle\r\n"
.$bound;

你需要设置:

$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n"
."<html><head></head><body>hey my <b>good</b> friend here is a picture of regal beagle</body></html>\r\n"
.$bound;

看起来它不会有太大的不同,在眼睛看来,它没有任何区别,但它确实对过滤器产生了影响。

最好的办法是让任何正在发送电子邮件的人也可以“查看原始”,在那里您可以获得电子邮件的整个代码,通常会在标题中给出垃圾邮件分数并且哪些测试失败,从而为您提供一些信息关于您需要做些什么来修复电子邮件以通过。

于 2013-08-05T11:05:51.677 回答