Change WordPress Email “Send From” Settings

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.

If you don’t want to set up email hosting for your site, the Change WP eMail From Details plugin is quick and easy to set up 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.

Screenshots

The blank plugin settings screen, after initial installation:

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

Notice the checkboxes; 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

/* 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 “[email protected]” in this code, it’s basically duplicating what WordPress already does by default. So maybe use “[email protected]” and make sure that’s an address that your users can reply to. Or use “[email protected]” to discourage reply emails.

/* 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 = "[email protected]";
$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”:

/* 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");

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

From “name” and “address” are highlighted by the red outlines

Adding Visual Flair To Your Emails

Taking customization a step further, several plugins allow you to specify a template for your emails. Not only can this make your emails more visually appealing but also enables you to keep some visual consistency between your site and emails that your users receive from you.

Screenshot of an templated email
Adding visual flair to your emails is easy

Install and activate the WP Better Emails plugin from the WordPress plugin repository and head to Settings > WP Better Emails.

First thing to notice is that this plugin provides its own overrides of the default From Name and From Email Address, so if you decide to use this plugin then you can disable and delete the Mail Change plugin we covered at the top of the article.

This plugin allows you to create both an HTML and plain text template to cater for all mail clients. The WYSIWYG editor is the same as that found in the editing screens, so you should feel at home.

All you really need to take care with is that you include %content% in both templates, otherwise your emails will effectively be empty! As well as the %content% tag, the plugin also caters for:

  • %blog_url% – WordPress Address (from Settings > General)
  • %home_url% – Site Address (from Settings > General)
  • %blog_name% – Site Title (from Settings > General)
  • %blog_description% – Tagline (from Settings > General)
  • %admin_email% – E-mail Address (from Settings > General)
  • %date% – Current date in format specified in Settings > General
  • %time% – Current time in format specified in Settings > General

To access this list at any time, click on the Help tab in the top right corner of the page.

It’s also possible to add your own tags using a filter provided by the plugin. See the plugin page for more details.

I think that the benefit this plugin provides is well worth the effort in setting it up. After all, the first email a reader will get from your site is when they register, so you want to make a good impression. There are no second chances with a first impression, as they say.

Customizing the Email Content

So, we’ve looked at changing the From Name and Email Address and putting a template around the email content. But what about the content itself?

Like me, you might think that this is fairly fundamental to running a site and that it should be available in the admin interface. The bad news is that the new registration (‘welcome’) email, for example, is about as far removed from the admin interface as is possible, being deeply embedded in the pluggable.php file in the wp-includes folder. Definitely somewhere we don’t want to go editing.

One other annoying aspect is that whilst the comment, trackback and pingback notifications all have filters applied to their subject and content, allowing them to be easily changed, the new user registration does not. Why there isn’t consistency across the emails only the WordPress gods know.

The good news is that Sean Barton has done the heavy lifting for us and created his SB Welcome Email Editor which enables the editing of the content for the following emails:

  • Welcome email to new user
  • New user notification to Admin
  • Forgot password (sent to user)

Install and activate the plugin and click on Settings > SB Welcome Email. There are a number of options to complete here and again you can set the From Email Address and From Name. You can also set whether to send the emails in text or HTML format and, of course, set the subject and body for the emails listed above.

Screenshot of the welcome email settings
Make a good first impression with a more welcoming Welcome email

As you can see from the above screenshot, this plugin plays really nicely with the WP Better Email plugin so if you want to use both I would recommend the following settings for SB Welcome Email:

  • From Email Address – leave blank (use settings from WP Better Email)
  • From Name – leave blank (use settings from WP Better Email)
  • Send Email As – TEXT
  • Set Global Email Headers – No

Keeping the emails as text means that WP Better Emails has no problems wrapping the content in its template and will also send out both an HTML and plain text version.

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

Free Video Why 100 is NOT a Perfect Google PageSpeed Score (*5 Min Watch) Learn how to use Google PageSpeed Insights to set realistic goals, improve site speed, and why aiming for a perfect 100 is the WRONG goal.
Tags: