PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

How to override wp_mail_from filter

  1. LumpySimon


    I'm using the wp_mail_from and wp_mail_from_name filters so that all WordPress emails come from "My Site" <> (rather than the default non-existent <> address).

    However, this filter is also overriding all my notifications sent by Gravity Forms.

    Is there a conditional test I can add to the filter function so that it doesn't run if the email is being sent by Gravity Forms?

    Here's the code I'm using:

    add_filter( 'wp_mail_from', 'send_mail_from' );
    add_filter( 'wp_mail_from_name', 'send_mail_from' );
    function send_mail_from() {
    	return get_option( 'wp_mail_from' == current_filter() ? 'admin_email' : 'blogname' );

    Many thanks

    Posted 11 years ago on Wednesday May 25, 2011 | Permalink
  2. There isn't anyway to do this from Gravity Forms as it simply calls the wp_mail function to execute sendmail functions. You would have to check with the WordPress CODEX or possibly one of the core WordPress developers to see if it's possible, i'm not aware of any specific way to do this.

    Posted 11 years ago on Wednesday May 25, 2011 | Permalink
  3. LumpySimon

    There turned out to be a simple way to do it: the wp_mail function is pluggable, so I've just copied the entire function but changed the lines that set the default address to use the admin_email and blogname functions.

    Posted 11 years ago on Wednesday May 25, 2011 | Permalink
  4. Hi,

    I would love to have a more precise description of how you solved this, LumpySimon. I did as you suggested and made my own custom function but nothing changes with Gravity Forms.

    Looking forward to your reply.


    Posted 10 years ago on Friday January 13, 2012 | Permalink