I'm using a code to send an email with an attachment, Email sending but the thing is it's going as spam. Can any one guess the reason? this is my code:
$to = 'krishna25@gmail.com';
$subject = 'PHP Mail Attachment Test';
$bound_text = "jimmyP123";
$bound = "--".$bound_text."
";
$bound_last = "--".$bound_text."--
";
$headers = "From: admin@server.com
";
$headers .= "MIME-Version: 1.0
"
."Content-Type: multipart/mixed; boundary=\"$bound_text\"";
$message .= "If you can see this MIME than your client doesn't accept MIME types!
"
.$bound;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"
"
."Content-Transfer-Encoding: 7bit
"
."hey my <b>good</b> friend here is a picture of regal beagle
"
.$bound;
$file = file_get_contents("http://reality.com/images/ezlogo.png");
$message .= "Content-Type: image/png; name=\"http://reality.com/images/ezlogo.png\"
"
."Content-Transfer-Encoding: base64
"
."Content-disposition: attachment; file=\"http://reality.com/images/ezlogo.png\"
"
."
"
.chunk_split(base64_encode($file))
.$bound_last;
if(mail($to, $subject, $message, $headers))
{
echo 'MAIL SENT';
} else {
echo 'MAIL FAILED';
}
A big mark down on spam filters is sending html content without a well formed html body.
ie. you have a section
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"
"
."Content-Transfer-Encoding: 7bit
"
."hey my <b>good</b> friend here is a picture of regal beagle
"
.$bound;
You need to set:
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"
"
."Content-Transfer-Encoding: 7bit
"
."<html><head></head><body>hey my <b>good</b> friend here is a picture of regal beagle</body></html>
"
.$bound;
it doesnt look like it would make much difference, and to the eye, it makes no difference, but it does make a difference to the filter.
the best thing to do would be to get whoever the email is being delivered too, to "view original", where you get the entire code of the email which usually gives a spam score in the headers and which tests failed, giving you some information on what you need to do to fix the email to pass.
In your code you showed the "from" address as below:
$headers = "From: admin@server.com
";
Make sure that this is a valid address that you are using.
Also, you could try setting additional headers such as Return-Path and Reply-To
$header .= "Reply-To: Admin <admin@server.com>
";
$header .= "Return-Path: Admin <admin@server.com>
";
Source - http://www.transio.com/content/how-pass-spam-filters-php-mail
Hope this helps!