Search code examples
wordpressemailspf

Sending SMTP emails reliably from Wordpress


I have a Wordpress site hosted at Cloudways. I have installed their Elastic Email SMTP add on. In theory I only need to activate the add on, and then the server will take care of STMP relay and authentication. Which means I don't need a SMTP plugin for Wordpress.

I have added a SPF value of v=spf1 a mx include:_spf.elasticemail.com ~all and a DKIM value of k=rsa;t=s;p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbmGbQMzYeMvxwtNQoXN0waGYaciuKx8mtMh5czguT4EZlJXuCt6V+l56mmt3t68FEX5JJ0q4ijG71BGoFRkl87uJi7LrQt1ZZmZCvrEII0YO4mp8sDLXC8g1aUAoi8TJgxq2MJqCaMyj5kAm3Fdy2tzftPCV/lbdiJqmBnWKjtwIDAQAB to my DNS settings, acording to Elastic emails own guidelines.

If send some test email trough a small PHP scrip on my server:

$to = "[email protected]";
$subject = "Testing";
$txt = "Hello world!";

mail($to,$subject,$txt,'From: [email protected] ','-f [email protected] ');

I get excellent score at www.mail-tester.com, and the email also arrive without problems at two different inboxes of mine.

But when I try to send email from wordpress, trough the plugin "check email" I get crappy score at www.mail-tester.com... It's says I'm not fully authenticated and I get -3 minus score for this line in particular: We didn't find a mail server (MX Record) behind your domain name xxxxxx.cloudwaysapps.com.

How comes I get so bad score when sending test email trough Wordpress compared to a simple php test script, and what should I do to get reliable score on outgoing mail from Wordpress?


Solution

  • The problem is that Wordpress has a default behavior of setting Return-Path to the server address, in my case: xxxxxx.cloudwaysapps.com instead of [email protected]. The solution and what also makes the email much more likely to reach an inbox is to modify the default behavior of Wordpress with this tiny plugin. It sets the Return-Path header of outgoing emails to equal the from email address.