Change WordPress Email “Send From” Settings

By default, your WordPress installation sends user registration emails from “[email protected]” For example, if your blog is at site.example.com, emails will come from [email protected]

Not good enough for me

If my real email address is [email protected] or [email protected], I want my WordPress emails “branded” with my real email address. The Change WP eMail From Details plugin is quick and easy to setup and does exactly what we want.

See the end of this post for a simple functions.php alternative, which is my preferred method because the Change WP eMail plugin isn’t from the WP Plugin Directory, and there are more files in the plugin’s folder than I would have expected necessary to achieve this functionality, plus some warnings from the Plugin Check plugin. I did verify both methods accomplish the stated goal – to customize the “from” email name and address.

Featured Plugin - WordPress Newsletter Plugin

Now there's no need to pay for a third party service to sign up, manage and send beautiful email newsletters to your subscriber base - this plugin has got the lot.
Find out more

Screenshots

The blank plugin settings screen, after initial installation:

The plugin settings screen with options filled out (courtesy of plugin’s webpage):

Notice the check boxes; they control the plugin's operation.

WordPress Email Settings

To be clear, the General Settings email address is used for receiving administrator emails, not the setting for outgoing emails.

The functions.php code

This is something you’d probably want out of your theme’s functions.php file and into a “functions plugin”. The code is the same, but use the plugin mentioned above (without these snippets), or use a functions plugin instead of your theme’s functions.php file.

Change the email address

Here are 2 functions.php snippets (use one or the other) to change the “from email address”:

Option 1

1
2
3
4
5
6
/* enter the full email address you want displayed */
/* from http://miloguide.com/filter-hooks/wp_mail_from/ */
function xyz_filter_wp_mail_from($email){
return "[email protected]";
}
add_filter("wp_mail_from", "xyz_filter_wp_mail_from");

Option 2 (functionality not available in the plugin)

I like this one because it’s easier to add to new websites. I don’t want to accidentally use “[email protected]” and then copy/paste to my client at xyz.com and have their emails look like they’re coming from lmnop.com’s site. If you put “wordpress@” in this code, it’s basically duplicating what WordPress already does by default. So maybe use “contact@” and make sure that’s an address that your users can reply to. Or use “noreply@” to discourage reply emails.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* auto-detect the server so you only have to enter the front/from half of the email address, including the @ sign */
function xyz_filter_wp_mail_from($email){
/* start of code lifted from wordpress core, at http://svn.automattic.com/wordpress/tags/3.4/wp-includes/pluggable.php */
$sitename = strtolower( $_SERVER['SERVER_NAME'] );
if ( substr( $sitename, 0, 4 ) == 'www.' ) {
$sitename = substr( $sitename, 4 );
}
/* end of code lifted from wordpress core */
$myfront = "whateverIwant@";
$myback = $sitename;
$myfrom = $myfront . $myback;
return $myfrom;
}
add_filter("wp_mail_from", "xyz_filter_wp_mail_from");

Change the Name

Here’s the snippet for changing the “from email name”:

1
2
3
4
5
6
/* enter the full name you want displayed alongside the email address */
/* from http://miloguide.com/filter-hooks/wp_mail_from_name/ */
function xyz_filter_wp_mail_from_name($from_name){
return "Best Name Ever";
}
add_filter("wp_mail_from_name", "xyz_filter_wp_mail_from_name");

Conclusion

Your email recipients (like new member registrations and post edit notifications) will see your plugin’s settings in action.

From "name" and "address" are highlighted by the red outlines

It’s as simple as that. Feel free to share your own experiences below.

Comments (6)

  1. We had to do something like this to get a WordPress installation with Gravity Forms to dump leads into our Goldmine CRM. The trick was in the “from:” and “to:” addresses and modifying the functions.php file and adding some code in the theme. Mail had to go to the WebImport decoder and took a little work from the folks at Gravity to make it happen.

    Since there still aren’t any business strength CRM packages for WordPress (I’ve looked at them all) other than a monthly with Salesforce.com, getting these things right are important. Thanks for the article.

    • Simple, good plugin idea. I like that it’s lightweight. I looked at the code and it’s literally just a few lines. My gut tells me not to trust the plugin I mentioned above, just because it seems so bloated. But I haven’t really looked into it in-depth.

  2. If you want to get the default site email address and the site title just copy/paste in functions.php


    /**
    * change WordPress default FROM email address
    **/
    add_filter('wp_mail_from', 'new_mail_from');
    add_filter('wp_mail_from_name', 'new_mail_from_name');
    function new_mail_from($old) {
    $email = get_option( 'admin_email' );
    return $email;
    }
    function new_mail_from_name($old) {
    $site_name = get_option( 'blogname');
    return $site_name;
    }

Participate