Prevent Sent Emails Treated as Junk Mails Using PHP Mail Function

PHP mail goes in spam and inbox

Use full headers to avoid spam

http://www.velvetblues.com/web-development-blog/avoid-spam-filters-with-php-mail-emails/

Prevent sent emails treated as junk mails using php mail function

PHP mail function goes to junk

If you are using a shared server than probably the score for that server is bad. If you are using your own server probably it's neutral but sometimes will go to spam because the server does not have a good reputation and depends how each email provider see that email.

Best solution I see it's to integrate a mailing service. In this way they promise that emails will not go to spam.
I don't know how many emails you are sending / month.
There are some that offer free email / month. Depends on volume.
For example:

  1. SendGrid - 12.000 free emails / month and they have official
    PHP library . Tested no problem with spam.
  2. MailGun - 10.000 free
    emails / month. Did not test this one but it's from rackspace
  3. Mandrill - no free emails, part of mailchimp. Tested no problem with spam.
  4. Amazon SES - 62.000 free emails / month for first year if you use free tier. Tested no problem with spam.

sending email via php mail function goes to spam

The problem is simple that the PHP-Mail function is not using a well configured SMTP Server.

Nowadays Email-Clients and Servers perform massive checks on the emails sending server, like Reverse-DNS-Lookups, Graylisting and whatevs. All this tests will fail with the php mail() function. If you are using a dynamic ip, its even worse.

Use the PHPMailer-Class and configure it to use smtp-auth along with a well configured, dedicated SMTP Server (either a local one, or a remote one) and your problems are gone.

https://github.com/PHPMailer/PHPMailer

How do I prevent mails sent through PHP mail() from going to spam?

You must to add a needle headers:

Sample code :


$headers = "From: myplace@example.com\r\n";
$headers .= "Reply-To: myplace2@example.com\r\n";
$headers .= "Return-Path: myplace@example.com\r\n";
$headers .= "CC: sombodyelse@example.com\r\n";
$headers .= "BCC: hidden@example.com\r\n";

if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>


Related Topics



Leave a reply



Submit