2012-09-21 96 views
0

可能重复:
How do you email source code without getting flagged as spam?
How can I lower the spam score of my email message?PHP - 电子邮件被标记为垃圾邮件

我使用下面的代码通过PHP附件的电子邮件。 (只是一个中等大小的图像和小的描述,没有任何垃圾邮件内容)

问题是,一些服务标记为垃圾邮件或完全拒绝它。

我是PHP新手,在SO上发现此代码。标题有什么问题或者是什么原因造成的?

<?php 
    $file   = $_POST["thefile"];   
     $text_message = $_POST["themessage"];  
     $subject  = $_POST["thesubject"];   
     $from   = $_POST["thesender"];   
     $to   = $_POST["theaddress"];     

      $attachment=uniqid(rand(), true) . '.png'; 

     $headers="From: $from\r\n"; 
     $headers.="Reply-to: $from\r\n"; 
     $headers.="Return-Path: $from\r\n"; 

    if (isset($_ENV["SERVER_NAME"])) 
     $headers.="Message-Id: <" . md5(uniqid(microtime())) . "@" . $_ENV["SERVER_NAME"] . ">\r\n"; 
    else 
     $headers.="Message-Id: <" . md5(uniqid(microtime())) . "@" . 'unknown' . ">\r\n"; 
    $headers.="Date: " . date("r") . "\r\n"; 
    $headers.="X-Mailer: PHP\r\n"; 
    if (isset($_ENV["REMOTE_ADDR"])) 
     $headers.="X-SenderIP: " . $_ENV["REMOTE_ADDR"] . "\r\n"; 
    else 
     $headers.="X-SenderIP: " . 'unknown' . "\r\n"; 
    if (isset($_ENV["SERVER_NAME"])) 
     $headers.="X-WebSite: " . $_ENV["SERVER_NAME"] . "\r\n"; 
    else 
     $headers.="X-WebSite: " . 'unknown' . "\r\n"; 
    $headers.="X-Script: SWF_Generator\r\n"; 
    $bound_text=md5(uniqid(time())); 

     $headers.="MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed; boundary=\"PHP-mixed-$bound_text\"\r\n"; 
     $message="--PHP-mixed-$bound_text\r\n"  
       ."Content-Type: text/html; charset=\"utf-8\"\r\n" 
       ."Content-Transfer-Encoding: 7bit\r\n\r\n" 
       ."<html><head></head><body>" 
       ."<div style=\"font-family: Arial, Helvetica, sans-serif; font-size : 1.3em; color: #000000;width: 100%;text-align: left;\">$text_message</div></body></html>\r\n\r\n" 
       ."--PHP-mixed-$bound_text\r\n" 
       ."Content-Transfer-Encoding: base64\r\n" 
       ."Content-Disposition: attachment; filename=\"$attachment\"\r\n" 
       ."Content-Type: image/png; name=\"$attachment\"\r\n\r\n" 
     .chunk_split($file) 
     ."\r\n\r\n" 
       ."--PHP-mixed-$bound_text--\r\n\r\n"; 

    mail($to,$subject,$message,$headers); 
} 
?> 

谢谢。

+1

发送通过信誉良好的电子邮件服务器,如您的Gmail帐户.... – Baba

+0

可能重复的[你如何通过电子邮件源代码没有被标记为垃圾邮件?](http://stackoverflow.com/questions/1809082/how-do -you-email-source-code-without-getting-flagged-as-spam)或http://stackoverflow.com/questions/1860937/how-can-i-lower-the-spam-score-of-my-电子邮件?rq = 1 – hakre

+0

巴巴说什么。电子邮件是否进入垃圾邮件文件夹取决于接收电子邮件的提供商 - 而不是由谁发送。 – Abluescarab

回答

1

好,发送使用PHP并不像调用mail()函数一样简单电子邮件...

我建议你使用一个有效的SMTP服务器(Gmail的一种,例如)和一个现成的php组件/类如PHPmailer

对于99%的情况,这应该足够了。

相关问题