Site Review: WordPress Code Snippets

Are you a WordPress admin, developer, designer, or otherwise creating WordPress sites? Do you struggle with finding good examples of the power of hooks and filters in customizing your WordPress installation?  Then you need to bookmark WordPress Code Snippets at wpsnipp.com[Read more…]

WordPress Email Settings: Changing the wp_mail address with a simple plugin

The ability to customize WordPress email settings in the admin panel is essentially non-existent.  So what if you want to change the default email address that WordPress sends email from.  Generically this is [email protected], and who wants that?  I know I don’t.  You probably don’t either.

In a previous post, I discussed how you can change your WordPress email settings to change this address with a simple filter snippet added to your theme’s functions.php file.  That’s my preferred method of customizing WordPress.

But what if you are a person that prefers the ease of loading a plugin to do your bidding? Well, adding these filters as a plugin is as simple as taking those filters, applying the appropriate plugin header, saving it as a php file, and loading it to your plugins folder.

Note: this particular process does not make use of admin panels.  While that makes for a nice interface for your WordPress email settings, it would also add needed bloat to the file. Simple edits to the email settings for the email address and name prior to saving is all you need for this project.  This results in a light weight and efficient plugin with the email settings you need.

I have created a code snippet you can use for this “quick-and-dirty” email settings plugin.  To implement, follow these steps:

  1. Save this file as a .php file.
  2. Open it in your favorite editor (or notepad).
  3. Change the email name and address in the functions to the name and address you want your email coming from.
  4. Save your changes.
  5. Load to your plugin folder.

There are several other plugins that can manage WordPress email settings with more features, so if that is what you are looking for, by all means, search the wordpress.org plugin directory.  But if you want something simple and light, this will do the trick!

For more information on testing, troubleshooting, and changing your WordPress email configuration for wp_mail, here are some additional posts:

Forcing translated field names when using translation files with WP-Members

WP-Members stores all of its registration field names and some of the user dialogs in the WordPress database.  If you are installing localized translation files for WP-Members on a WordPress installation where you have already activated the WP-Members plugin, you will likely find that the translated fields names do not load into the database.  [Read more…]

Changing the wp_mail from address in WordPress without a plugin

One common question I often hear regarding WordPress email configuration is, “How do I change the email address from [email protected]?”  I suspect that most people are unaware that WordPress has its own function for sending email and that it has a default address that it sends from.  If they are aware, most users opt for changing this with a plugin.

WordPress has no ability to manage email settings via its admin panel, but that is not to say that you cannot manage the email configuration at all.  It actually is pretty flexible.  You can even change your WordPress email configuration to send via an SMTP server; a method much more reliable than the generic email script.  But I’m getting ahead of myself.

If your sole aim is to change the email “from” address to something that is not the default value, this is far to simple for using a plugin (unless you have complicated needs and want more control over email configuration in the WordPress admin panel).

Don’t get me wrong.  There are quite a few plugins that do this, and if you feel more comfortable doing it that way, by all means, add another plugin to the list of things your blog needs to load.  But if you are brave enough to do something quick, easy, and lightweight, by all means read on!

wp_mail and some relatives

WordPress relies on a function called wp_mail to send email.  This function is essentially a wrapper for the phpmailer class.  The problem is that the wp_mail default email “from” address cannot be configured via the WordPress admin panel.  But the fortunate thing is that this function and its related functions are both pluggable and can be filtered.  Our example here is to simply opt for a filter. wp_mail relies on some other outside information, some of which is wp_mail_from (an email address) and wp_mail_from_name (the real name given to the email address).  Since that is all we want to change, we are just going to filter those.

Filtering the email address

Add a filter for the email address using ‘add_filter’:

add_filter( 'wp_mail_from', 'my_mail_from' );
function my_mail_from( $email )
{
	return "change-this-to-your-email-address";
}

Filtering the email name

Now add a filter for the name of the email address:

add_filter( 'wp_mail_from_name', 'my_mail_from_name' );
function my_mail_from_name( $name )
{
	return "My Name";
}

The functions.php file

That’s great, but what do I do with it? I’m glad you asked.  Add these two filters and their accompanying functions to your theme’s functions.php file.  You don’t even need to mess with a file editor and ftp for this.  I would simply go to the Appearance > Editor menu in the WP Admin Panel, then find ‘functions.php’ in the list of theme files on the right.  Add these filters and you are in business.

Easy peasy lemon squeezy.  And no bloated plugin to slow down your site!

If you’d rather use a plugin to handle WordPress email configuration instead of the functions file, that’s covered in this post.

For more information on testing, troubleshooting, and changing your WordPress email configuration for wp_mail, here are some additional posts: