Fixing the WordPress Email Return-Path Header

WordPress LogoEmails sent by WordPress can often end up in the spam folder because of a sub-optimal Return-Path email header. What does that mean and how do you fix it?

The best way to illustrate this problem is with an example. Say you installed WordPress on a server with a Fully Qualified Domain Name (FQDN) of However, the domain name of your WordPress site is In the WordPress admin area under Settings > General you’ve set as your site’s outgoing email address. The only problem is that the mail server software (MTA), such as Sendmail or Postfix, is adding a return-path header to your WordPress emails that looks something like the following:

Return-Path: <>

This does not match the from address of and that is why some spam filters would flag this email as junk mail. So ideally you want the return-path header to match the from header in emails sent by WordPress.

Fixing The Return-Path Header

WordPress has its own function for sending emails called wp_mail which you can find in wp-includes/pluggable.php. To set the correct return-path header you have to plug into the action “phpmailer_init” that is executed just before an email is sent out:

Plugin Name: Email Return Path Fix
Author: Abdussamad Abdurrazzaq
class email_return_path {
  	function __construct() {
		add_action( 'phpmailer_init', array( $this, 'fix' ) );    
	function fix( $phpmailer ) {
	  	$phpmailer->Sender = $phpmailer->From;
new email_return_path();

The above plugin sets the return-path header to equal the from header.

If you are using sendmail on your server you have to take an additional step and add the web server username (usually apache) to your /etc/mail/trusted-users file and restart sendmail. If you don’t do this sendmail will add an X-Authentication-Warning header which is likely to cause your email to end up in the spam folder. You don’t have to take this step if you are using Postfix.

Kudos to Stefano Lissa on the WP forums for writing about this.

9 thoughts on “Fixing the WordPress Email Return-Path Header

    • There can be many reasons for this. Some things you can try are setting an SPF record in your DNS settings for your domain name and implementing DKIM. It would probably be easier to just use a specialist SMTP service like mailgun, mandrill, amazon SES etc. These days it is very hard for a new IP address to build up a good reputation and get accepted as legitimate by the major free email providers. That is why these transactional email providers have made space for themselves.

Leave a Reply

Your email address will not be published. Required fields are marked *