I have several other posts on how to improve the reliability of email sent via wp_mail and how to troubleshoot your WordPress email settings. Most of these posts focus on sending email. But WordPress email sent to spam is also a common problem.
How can you optimize WordPress email to make messages less likely to end up flagged as spam by the receiver?
How you set up WordPress email matters, and this simple change will fix the problem.
Review the email’s return path in the header. By default, WordPress does not create email headers. Most of the time this is a non-existent email address that matches your domain or your server. This might be based on your host – especially if you are on a shared host.
Prevent WordPress email sent to spam with this:
The code snippet below will prevent WordPress email sent to spam. Add it to your functions.php file (or wherever you keep custom code snippets). This will change the email return path to match the “from” address:
add_action( 'phpmailer_init', 'fix_my_email_return_path' ); | |
function fix_my_email_return_path( $phpmailer ) { | |
$phpmailer->Sender = $phpmailer->From; | |
} |
When you match the return path to your “from” address, you reduce the likelihood of your messages going to spam. (Make sure your “from” address is a real address.)
So what’s going on here?
wp_mail
relies on the phpmailer class. WordPress has an action hook in the phpmailer initialization (phpmailer_init). Use this action to make the “Sender” (return-path) the same as the “From” address.
When you configure WordPress to send email through an SMTP email server, this process is likely already done. This only applies to email from the web server’s email server.
If your WordPress site sends email to users, make sure you optimize email settings to reduce the likelihood of spam rejection. But don’t miss the links in the article above. There are other techniques discussed to help make your email more robust.
Enjoyed this article?
Don't miss a single post. Subscribe to our RSS feed!