Change WordPress Email “Send From” Settings

By default, your WordPress installation sends user registration emails from “wordpress@top-level-domain.com” For example, if your blog is at site.example.com, emails will come from wordpress@example.com.

Continue reading, or jump ahead using these links:

I Don’t Want to Use the Default WordPress Email
Change WP eMail From Details Screenshots
WordPress Email Settings
The functions.php code
Customizing the Email Content

I Don’t Want to Use the Default WordPress Email

If my real email address is cliff@example.com or businessname@gmail.com, 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.

Change WP eMail From Details Screenshots

The blank plugin settings screen, after initial installation:

The plugin settings screen with options filled out (courtesy of the 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 «daffy.duck@example.com»;
}
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 “me@lmnop.com” 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.

/* 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”:

/* 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

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 the 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.

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.

Щелкните ниже, чтобы поставить оценку!
Всего: 0 В среднем: 0

Написать комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *