'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 1:[1]
For WordPress, the actual problem is what you have identified in your second comment.
There is another workaround if you use “WP Mail SMTP" plugin on your WordPress site. It overrides the default WordPress email behavior with your customized settings.
Cloudways has written a complete guide on setting up SMTP on WordPress. In their example, they have used Gmail SMTP, but the steps are same for Elastic Email.
Solution 2:[2]
You can also code this very quickly in the functions.php theme file. For example:
function my_phpmailer_example( $phpmailer ) {
$phpmailer->ReturnPath='[email protected]';
$phpmailer->Sender='[email protected]';
$phpmailer->SetFrom('[email protected]', 'My Name', FALSE);
}
add_action( 'phpmailer_init', 'my_phpmailer_example' );
In my experience, actively setting all three of these entries explicitly will really help with dkim and spf validation issues.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mustaasam Saleem |
| Solution 2 | AdamJones |
