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:

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

  4. Kurt says:

    Hello Chad,
    I’am desperate.
    The last days I try to create this filter

    I follow the steps in the other articel. But it dosn’t work.

    Now I read this and see the link: http://butlerblog.com/wp-downloads/qnd-wp-mail.phps

    I think that I nead somethink like this to put in the wp-members-pluggable.php ?

    The Members plugin is fantastic for me in the basic function, but I need to change a few things.

    1. A redirect after login to a members page.
    2. A logout redirect to my blog.
    3. When someone is not yet a member than can find a page and scroll around. Basicly when they click on a category the system tell them that they have to be a member. Thats ok, BUT the system basically shows also the registration form. In my case the registration form have only to be shown after payment.

    Can you help me out of this, please.

    Grtz,

    Kurt

  5. haneul says:

    hey can you show me exactly where on the php file i have to change to my email.

Leave a Reply

Comments are welcome.
Your email address will not be published.
Required fields are marked *.
Please consider the following before posting your comment:

  • Comments are moderated, so your comment may not show up right away. Submit only once!
  • Keep things on topic. If you comment is not relevant to the specific post, it will be deleted.
  • NO soliciting of services is allowed! These comments will be deleted and the user banned.
  • If you are asking for support, please consider looking for the answer in the Quick Start Guide, the Users Guide, and the FAQs first.

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>