Viewing 7 replies - 1 through 7 (of 7 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    Looks like those can be custom set by using the 4th argument for wp_mail() function calls, but we never get to that point, so our plugin at least defaults to all of WordPress’ default values.

    That said, WordPress core does have some filters that can be used to set the “From name” and “From email”.

    	/**
    	 * Filters the email address to send from.
    	 *
    	 * @since 2.2.0
    	 *
    	 * @param string $from_email Email address to send from.
    	 */
    	$from_email = apply_filters( 'wp_mail_from', $from_email );
    
    	/**
    	 * Filters the name to associate with the "from" email address.
    	 *
    	 * @since 2.3.0
    	 *
    	 * @param string $from_name Name associated with the "from" email address.
    	 */
    	$from_name = apply_filters( 'wp_mail_from_name', $from_name );
    

    The thing with these is that they would be global to all uses of wp_mail() at this point, and not just our emails.

    If you need some help working with the filters, I can provide some example usage for them.

    Thread Starter beetcore

    (@beetcore)

    Hi, thanks for the prompt response…

    Pls how do i add these filters to change the “From name” and “From email”.

    I’ll appreciate your step by step guidance.

    Thanks

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Basic example, but these would go in your active theme’s functions.php

    function beetcore_change_from_email( $original ) {
    	return '[email protected]';
    }
    add_filter( 'wp_mail_from', 'beetcore_change_from_email' );
    
    function beetcore_change_from_name( $original ) {
    	return 'Foo Bar';
    }
    add_filter( 'wp_mail_from_name', 'beetcore_change_from_name' );
    
    Thread Starter beetcore

    (@beetcore)

    Hi, thanks for this…
    Can i substitute what you have there with mine, e.g.

    —————

    function beetcore_change_from_email( $original ) {
    return ‘[email protected]’;
    }
    add_filter( ‘wp_mail_from’, ‘beetcore_change_from_email’ );

    function beetcore_change_from_name( $original ) {
    return ‘Support Beetcore’;
    }
    add_filter( ‘wp_mail_from_name’, ‘beetcore_change_from_name’ );

    ——————

    Will above work?

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Looks fine to me, and of course you can change those spots, I just put in dummy text to demo it all.

    Thread Starter beetcore

    (@beetcore)

    It created an error https://prntscr.com/jtob72
    I guess cos i use PageLines Framework…

    So i googled it and came across this plugin CB Mail Sender, which solved the challenge.

    Thanks a lot ??

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Odd that that’s causing an internal server error. The only source I can think of for it would be “bad” quotes due to copy/paste from the forum here.

    Regardless, you have something working now, which is the important part.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Change Sender Email From WordPress’ is closed to new replies.