-2

Possible Duplicate:
PHP: How to avoid a system generated e-mail going into spam?
How to send 100.000 emails weekly?

I am using the following script to send mail

$to  = 'name@test.com' . ', '; 
$to .= 'name2@test.com';

$subject = 'Green apple';

$message = 'Enquiry posted by test ';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


$headers .= 'From: Green Apple <info@greenappleme.com>' . "\r\n";


if (mail($to, $subject, $message, $headers))
{
    echo "mail send successfully";
}
else  
    echo "mail can't send";

When I use this script to some servers, the mail is going to spam. But in some servers, it is going to the Inbox as desired.

How can I prevent email going to spam?

Community
  • 1
  • 1
Sainul Abid
  • 99
  • 1
  • 9

3 Answers3

1

To prevent an email going into spam, don't send with mail from PHP. Send it with SMTP from your server, you can use PHP to connect to SMTP and submit the message. You will then need to set the SPF records on your server, and reverse DNS records with whoever your IP address comes from. If you do these three things then you'll be on the whitelist and all your emails will go into the inbox everywhere, assuming you don't abuse the privilege and get put on a blacklist.

So: send using SMTP, research SPF records and reverse DNS.

You won't be able to do this unless you have a dedicated server with dedicated IP for the domain from which you are sending the email from.

Alasdair
  • 13,348
  • 18
  • 82
  • 138
0

Be sure to set the RETURN PATH as the optional 5th parameter to the mail() function.

if (mail($to, $subject, $message, $headers, '-finfo@greenappleme.com'))
Yes Barry
  • 9,514
  • 5
  • 50
  • 69
0

TO send ur majority mail in inbox set below headers and dont use test like keywords in your subject line

$headers  = "From: My site<noreply@example.com>\r\n";
$headers .= "Reply-To: info@example.com\r\n";
$headers .= "Return-Path: info@example.com\r\n";
$headers .= "X-Mailer: Drupal\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
Sonal Khunt
  • 1,876
  • 12
  • 20