WordPress – How to add Sender header to outgoing emails

The following WordPress PHP function will automatically add the Sender email header to outgoing emails.

This can help with deliverability by giving the email more information that spam filters use to verify it’s authenticity.

If you’re not sure where to place this code I highly recommend you read How to create a WordPress plugin for your custom functions.

 

class ITSG_Set_Sender_Address_Email {
     function __construct() {
          add_action( 'phpmailer_init', array( $this, 'set_sender_address' ) );
     }

     function set_sender_address( $phpmailer ) {
          $phpmailer->Sender = $phpmailer->From;
     }
}

new ITSG_Set_Sender_Address_Email();