Phpmailer - Mails Going Straight to Spam

PHPMailer - mails going straight to spam

This does sound more like a configuration issue with your mail server and/or your DNS server. Your mail server does not appear to be "trusted" enough, so you don't get enough "positive" points from GMail (and mail clients). I notice that you're using postfix as your mailer... Have you configured it properly?

I would suggest you configure postfix first. For example, here's a guide on how to do it in CentOS:

http://wiki.centos.org/HowTos/postfix

Second, you should add an SPF record to your DNS server:

http://en.wikipedia.org/wiki/Sender_Policy_Framework

Third, it would be good to have a reverse lookup entry for your server:

http://en.wikipedia.org/wiki/Reverse_DNS_lookup

You will need to do the above and some more to make sure that clients don't flag your mail as spam, and you don't get blacklisted

Here's a good list of things to do to avoid getting blacklisted:

https://www.supportsages.com/prevent-your-mailip-from-getting-marked-as-spamblacklisted-a-few-tips/

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

Everytime my mail goes to spam in phpmailer

Based on you code i notice that you are sending an email directly from you web page on your domain.

For example you used an @hotmail.com address.

When the recipient receive the emails the mail service of the recipient may test a reverse DNS of the sender of the mail. So the sender is from @hotmail.com but the mail comes from your domain which of course is not hotmail.com.

So I receive a mail from an address @hotmail.com but the IP sender isn't related at all with domain hotmail.com: that's SPAM!

http://en.wikipedia.org/wiki/Reverse_DNS_lookup

I think a possible solution is: in you PHP code use authenticate with SMTP and from there send the mail!

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

PHPMailer goes to spam

Apart from the possibility that your server may be blacklisted for some reason, the most common cause for emails landing in spam servers that i encountered is that the from-address and the server's name do not match.

Consider a from-address like someone@mydomain.com sent from a server cheapwebhosting.com, the recipient mail server sees the discrepancy and will most likely consider this a spam message.

So, you should check the message headers of a test email if something like this is happening here (or if you notice anything else that looks fishy)



Related Topics



Leave a reply



Submit