• Resolved houseofhands

    (@houseofhands)


    I use the following snippet in order to change WordPress default FROM email address.

    add_filter('wp_mail_from', 'new_mail_from');
    add_filter('wp_mail_from_name', 'new_mail_from_name');
    
    function new_mail_from($old) {
     return '[email protected]';
    }
    function new_mail_from_name($old) {
     return 'yourdomain.com';
    }

    Because of this piece of code, the FROM field in Notifications does not work. Whatever email address you put in there, the email is always send from the address in the above snippet.

    Is there a way to still use the snippet, but with an exception for the Advanced Forms FROM field?

    Thanks in advance!

    • This topic was modified 4 years, 5 months ago by houseofhands.
    • This topic was modified 4 years, 5 months ago by houseofhands.
    • This topic was modified 4 years, 5 months ago by houseofhands.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi!

    This might be a bit challenging. What you can do is add an if statement in your current snippet to check if $old is the from address you’re expecting from the plugin, and if so don’t change it. Would that work?

    Thread Starter houseofhands

    (@houseofhands)

    Hi Fabian,

    Thanks for your reply!

    That’s exaclty the solution I was looking for, but I’m not sure how to target the (Advanced Forms) from address field.

    Can you give me some pointers?

    • This reply was modified 4 years, 4 months ago by houseofhands.
    Plugin Author fabianlindfors

    (@fabianlindfors)

    It could look something like this:

    
    add_filter('wp_mail_from', 'new_mail_from');
    add_filter('wp_mail_from_name', 'new_mail_from_name');
    
    function new_mail_from($old) {
     if ( $old == 'FROM_EMAIL_USED_IN_AF' ) return $old; 
     return '[email protected]';
    }
    function new_mail_from_name($old) {
     if ( $old == 'FROM_NAME_USED_IN_AF' ) return $old;
     return 'yourdomain.com';
    }
    

    When setting up the email in AF you can set the name and address like this: Name <[email protected]>.

    Thread Starter houseofhands

    (@houseofhands)

    I still don’t see it, because in my case the FROM name + address in AF are not fixed. The FROM is the name + address of whoever fills out the form. So I use the ‘insert field’ to select the email field. Do you see what I mean?

    In the meantime I will tinker around with the code you’ve provided. Thanks for that!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘From Email Address in Notifications’ is closed to new replies.