ButlerBlog

chad butler's weblog

  • About
  • Blog
  • WordPress Plugins
  • Contact
Home / Web / WordPress / Prevent WordPress email sent to spam with this

Prevent WordPress email sent to spam with this

By Chad Butler 1 Comment

Prevent WordPress email sent to spam with this

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;
}
view raw return_mirror_sender.php hosted with ❤ by GitHub

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!

  • Facebook
  • Twitter
  • Email
  • Print
  • More
  • LinkedIn
  • Reddit
  • Tumblr
  • Pocket
  • Pinterest

Filed Under: Blogging Tips, WordPress Tagged With: webdev, WordPress, WordPress Email Configuration, WordPress Site Management, wp_mail

About Chad Butler

Chad Butler is a freelance writer and web developer. He has developed several popular WordPress plugins and has written for forbes.com, sfomag.com, and investopedia.com. He also runs a small organic farm in east Georgia.

Join Us!

I will never share your information. No spam. No junk. No kidding. Unsubscribe anytime.

Recent Posts:

  • Mastering the Art of Crafting SMART Marketing Goals
  • Rediscover Your Brand Story: 7 Tips for Refreshing Your Company Identity
  • Creating Engaging Content: Tips for a Successful Content Marketing Strategy
  • After a Layoff or Underemployment: Ingenious Ways to Make Extra Money
  • Essential Tips for Freelancers Applying for a Mortgage
  • 5 Steps to Crafting Your Market Research Strategy
  • Revolutionizing Your Content Strategy: How AI Can Improve Your Content Marketing Efforts
  • Leveraging Content Marketing to Give Your Small Business an Edge in Today’s Digital Marketplace
  • Simple Tactics for Protecting Your Small Business Against a Recession
  • Create and delete WordPress sites in XAMPP with a simple batch file

Archives

  • About
  • Blog
  • Archive
  • Contact

Site powered by WordPress, running on the Genesis Framework from StudioPress.

Unless otherwise noted, content on this site is © 2006-2023 ButlerBlog and may not be reproduced without express written permission from the author.

Some content may include affiliate links for which this site receives a small commission.