-1

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."\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';
}
batMask
  • 734
  • 3
  • 17
  • 35
  • 4
    If it's being marked as spam, this is *usually* due to the content. If you can get hold of a copy of the email post-spam checking and look at the raw headers it'll often state the main reason the email was marked as spam. Irrespective, this isn't a coding issue - it's a content one. – John Parker Aug 05 '13 at 10:53
  • Possibly duplicate of [this post](http://stackoverflow.com/questions/8075400/mail-generated-in-php-going-to-spam). – Deepak Biswal Aug 05 '13 at 10:55
  • 2
    email sent from a different server than the `from` email address is easily marked as spam. – Reactgular Aug 05 '13 at 10:55
  • look at the headers of the email in the spam folder -- most spam filters add headers to the message that show the rules that caused it to be marked as spam. – Spudley Aug 05 '13 at 13:20

2 Answers2

1

In your code you showed the "from" address as below:

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

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>\r\n"; 
$header .= "Return-Path: Admin <admin@server.com>\r\n";

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

Hope this helps!

danw3108
  • 35
  • 6
1

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\"\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;

You need to set:

$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;

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.

bizzehdee
  • 20,289
  • 11
  • 46
  • 76
  • Appreciate bro, When change it mail spam is stoped, but my attachment image shown as garbage (BLOB). I cannot find my attachment. – batMask Aug 05 '13 at 12:10
  • sorry, put the ` – bizzehdee Aug 05 '13 at 12:14
  • Oh! again spam now, but the attachment is fine. – batMask Aug 05 '13 at 12:23
  • this is just one of many things you have to do to avoid a filter, it more than likely will not be one single thing causing it, as i said, check the email as it is received and see what is triggering the spam from the email headers. – bizzehdee Aug 05 '13 at 12:25