PHP - Email gets flagged as spam
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1809082/how-do-you-email-source-code-without-getting-flagged-as-spam">How do you email source code without getting flagged as spam?</a><br>
  <a href="http://stackoverflow.com/questions/1860937/how-can-i-lower-the-spam-score-of-my-email-message">How can I lower the spam score of my email message?</a>  </p>
</blockquote>



<p>I'm using the code below to send an email with attachment through PHP. (Just a medium sized image and a small description without any spam ish content) </p>

<p>The problem is that some services flagging the email as spam or completely reject it.</p>

<p>I'm new to PHP and found this code here on SO. Is there anything wrong with the headers or what could cause this?</p>

<pre><code>&lt;?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: &lt;" . md5(uniqid(microtime())) . "@" . $_ENV["SERVER_NAME"] . "&gt;\r\n";
    else
        $headers.="Message-Id: &lt;" . md5(uniqid(microtime())) . "@" . 'unknown' . "&gt;\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"  
                ."&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;"
                ."&lt;div style=\"font-family: Arial, Helvetica, sans-serif; font-size : 1.3em; color: #000000;width: 100%;text-align: left;\"&gt;$text_message&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;\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);
}
?&gt;
</code></pre>

<p>Thank you.</p>
