Possible Duplicate:
How do you email source code without getting flagged as spam?
How can I lower the spam score of my email message?
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)
The problem is that some services flagging the email as spam or completely reject it.
I'm new to PHP and found this code here on SO. Is there anything wrong with the headers or what could cause this?
<?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);
}
?>
Thank you.