Developer // WordPress Mail Overwriting Return-Path Header

After being told that emails sent from a client’s Wordpress site had suddenly started getting rejected I immediately assumed an SPF problem.

But when investigating the headers it became apparent that the return-path header getting set didn’t match what was being sent out.

After googling it became clear that WordPress was getting this from the server. Overriding any headers set in the wp_mail send function.

Luckily I found a great fix function on, which re-sets the path using the from value in the header.
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();

Handy little snippet to remember for future.


Leave a Reply

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