PHP Email - How to Avoid Mail Ending Up in Spam Box

php email - how to avoid mail ending up in spam box

It has nothing to do with the PHP code but make sure that the email are being sent from a domain that is hosted on the server. That means it would be a bad idea to use your gmail address for sending though PHP. Every email that leaves the server needs to be signed and needs to have SPF records

This is usually because in the DNS a correct SPF record has not been setup. This can be easily done depending on the software you use. If you use cPanel then this is pretty much a two step process.

Some links:
http://www.emailquestions.com/help-desk/2418-why-do-my-own-emails-go-into-spam.html
http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=spf+records
http://www.techtalkpoint.com/articles/setting-up-spf-records-in-cpanel-whm-and-namecheap/

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!";
}
?>

How to avoid my mails sent from PHP mail() being marked as spam?

The php mail() function has nothing to-do with your emails being marked as spam.

That an email is being marked as spam happens on the other end. You can not influence the process much with mail() - as it's the other end.

There can be thousand of reasons why an email is being marked as spam, and as long as you don't know the concrete reason why your email is being marked as spam, you can do nothing against that.

There is a whole industry which makes a living of that btw.

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 you make sure email you send programmatically is not automatically marked as spam?

Use email authentication methods, such as SPF, and DKIM to prove that your emails and your domain name belong together, and to prevent spoofing of your domain name. The SPF website includes a wizard to generate the DNS information for your site.

Check your reverse DNS to make sure the IP address of your mail server points to the domain name that you use for sending mail.

Make sure that the IP-address that you're using is not on a blacklist

Make sure that the reply-to address is a valid, existing address.

Use the full, real name of the addressee in the To field, not just the email-address (e.g. "John Smith" <john@blacksmiths-international.com> ).

Monitor your abuse accounts, such as abuse@yourdomain.example and postmaster@yourdomain.example. That means - make sure that these accounts exist, read what's sent to them, and act on complaints.

Finally, make it really easy to unsubscribe. Otherwise, your users will unsubscribe by pressing the spam button, and that will affect your reputation.

That said, getting Hotmail to accept your emails remains a black art.

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

E-Mails of PHPMailer still getting into SPAM on some clients even after adding SPF-record

Whether mail ends up in spam is very difficult to control. Implementing SPF and DKIM can help, but still provide no guarantees. If it was easy to bypass spam filters, spammers would do it, and they would not be spam filters! There's an article in the PHPMailer wiki about avoiding spam filters that you may find helpful. The headers in a received message will often tell you why a message has been put in the spam folder, for example listing the spamassassin rules it matched.

You say it works "manually", but is that sending from the same place (e.g. on your local machine)? You can get the raw text of messages sent through each route and compare them to see what's different (other than obvious things like message IDs).

That MailGun article is outdated. Since then, RFC8314 has not only "undeprecated" port 465, it's now recommended as the default because it eliminates a possible attack vector in the pre-encryption stage that SMTP+STARTTLS uses on port 587. Unfortunately it also makes it harder to debug from PHP, and denies the chance to do opportunistic encryption when encryption is not requested explicitly, so it's not the default in PHPMailer (yet).

sending email with PHP (preventing from being placed in spam folder)

In general, email is classified as spam or not spam on the receiving end, not the sending end - otherwise, spammers would simply say that all of their messages aren't spam, completely defeating the purpose. Thus, you can't just force a message to go to a sender's inbox.

However, what you may need to do is see if the machine that you're using to send mail is currently listed on any spam blocklists, and if so, take the necessary steps to remove it from those blocklists. The most common is probably Spamhaus.



Related Topics



Leave a reply



Submit