• I’ve been struggling to change the FROM name on DWQA’s emails sent to end users.
    If I set a from address in the plugin email settings, it arrives from “WordPress <[email protected]>”
    If I set the FROM setting to “Email Name <[email protected]>”, it gets compressed by the sanitize_email function, so that doesn’t work.

    I ended up editing inc/Notifications.php thus:

    	public function get_from_name(){
    		return 'Email Name';
    	}
    
    	public function send( $to, $subject, $message, $headers = '', $attachments = array() ) {
    		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
    		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
    		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
    
    		$sended = wp_mail( $to, $subject, $message, $headers, $attachments );
    
    		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
    		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
    		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
    		return $sended;
    	}
    

    Obviously that’s not ideal, so could the get_from_address function split the email address up if it’s in the ‘Name <address>’ format, or could you add another box in the settings for the FROM display name?
    Or am I missing something?

    Thanks

    • This topic was modified 7 years, 8 months ago by snick.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to set email From name’ is closed to new replies.