Customize WordPress email headers

On many systems using the default WordPress configuration, emails originating from a WordPress site will likely have some undesirable traits. These are:

From: WordPress

It’s likely you’ve seen this before. It’s pretty much the default. The problem is, it’s useless most of the time.

Let’s fix that.

Change the values in the function below and add this code to your functions.php, or make it a plugin and activate it.

Plugin Name: John's Rewrite phpmailer Sender
Plugin URI:
Description: Rewrites mail_from (From), from_name (FromName), and Return-Path (Sender).
Version: 0.10
Author: John Parris
Author URI:
License: GPLv2

function wp_mail_to_smtp( $phpmailer ) {
    $phpmailer->Sender   = '';
    $phpmailer->From     = '';
    $phpmailer->FromName = 'From Name';
add_action('phpmailer_init', 'wp_mail_to_smtp');