Changing the wp_mail “from” address with a plugin

In a previous post, I discussed the ease of filtering the “from” address that wp_mail will send email from. This was done using a filter added to your theme’s functions file (functions.php).  I always prefer using the functions file for simple filters and actions as a plugin is often overkill for what is necessary. 

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 to make edits. This would add considerable unnecessary bloat to the file. Simply edit the returned values for email address and name in the file prior to saving.  This results in a light weight and efficient plugin.

I have created the needed code for this “quick-and-dirty” 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 accomplish this 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 it.

About Chad

Chad Butler is both a freelance writer and web developer. He has developed several popular WordPress plugins and his writing has appeared on forbes.com, sfomag.com, and investopedia.com.
This entry was posted in WP-Members and tagged , , , , . Bookmark the permalink.

Related Posts:

4 Responses to Changing the wp_mail “from” address with a plugin

  1. Adan says:

    Sweet ! You saved me. This was very helpful, keep the good work.

  2. Dez says:

    Doesn’t work for me sadly, WP 3.2.1

    • Chad says:

      Dez – thanks for the comments, but you would have to be doing something wrong if it’s not working for you. This is nothing more than a filter for an internal WordPress function that is (and has been) pluggable for quite a number of versions and hasn’t changed (nor would I expect it to for the forseeable future – including 3.3 which I am beta testing now). I would suggest rereading the instructions and make sure you didn’t miss something.

  3. Luxury says:

    First, Chad, thank you!

    Dez,
    Do the next steps :

    1. make a folder in a plugin directory named “quick-and-dirty”
    2. upload the file php modified from above in it
    3. activate the plugin

    It works!
    Thank you again Chad!
    C.

Leave a Reply

Your email address will not be published. Required fields are marked *.
Comments are moderated. Please submit only once.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>