• Resolved jamestoronto

    (@jamestoronto)


    //// if From Email is Yahoo
    function wp_mail_smtp_dev_reply_to( $args ) {

    $reply_to = ‘Reply-To: [email protected]‘;

    if ( ! empty( $args[‘headers’] ) ) {
    if ( ! is_array( $args[‘headers’] ) ) {
    $args[‘headers’] = array_filter( explode( “\n”, str_replace( “\r\n”, “\n”, $args[‘headers’] ) ) );
    }

    // Filter out all other Reply-To headers.
    $args[‘headers’] = array_filter( $args[‘headers’], function ( $header ) {
    return strpos( strtolower( $header ), ‘reply-to’ ) !== 0;
    } );
    } else {
    $args[‘headers’][] = “”;
    }

    $args[‘headers’][] = $reply_to;

    return $args;
    }

    add_filter( ‘wp_mail’, ‘wp_mail_smtp_dev_reply_to’, PHP_INT_MAX );

    • This topic was modified 3 years, 1 month ago by jamestoronto.
Viewing 1 replies (of 1 total)
  • Plugin Support Darshana

    (@darshanaw)

    Hi @jamestoronto,

    Thank you for sharing your code with other users. Yahoo is a strict email provider and does not accept emails with different “reply-to” email addresses other than the “from email” address.

    /**
     * Add Yahoo email as Reply-To header for outgoing WordPress emails.
     *
     * @param array $args Email arguments.
     *
     * @return array Modified email arguments.
     */
    function wp_mail_smtp_dev_reply_to( $args ) {
    	$reply_to = 'Reply-To: [email protected]';
    
    	if ( ! empty( $args['headers'] ) ) {
    		if ( ! is_array( $args['headers'] ) ) {
    			$args['headers'] = array_filter( explode( "\n", str_replace( "\r\n", "\n", $args['headers'] ) ) );
    		}
    
    		// Filter out all other Reply-To headers.
    		$args['headers'] = array_filter( $args['headers'], function ( $header ) {
    			return strpos( strtolower( $header ), 'reply-to' ) !== 0;
    		} );
    	} else {
    		$args['headers'][] = '';
    	}
    
    	// Add Yahoo email as the Reply-To header.
    	$args['headers'][] = $reply_to;
    
    	return $args;
    }
    add_filter( 'wp_mail', 'wp_mail_smtp_dev_reply_to', PHP_INT_MAX );

    Thanks!

Viewing 1 replies (of 1 total)

The topic ‘Hook for using Yahoo Email in DIVI’ is closed to new replies.