Home / Admin / Set a Custom Reply-To Email
Duplicate Snippet

Embed Snippet on Your Site

Set a Custom Reply-To Email

This snippet will ensure all emails sent from your site have the same reply-to email address.

On line 8, you’ll need to replace Pattie Paloma and [email protected] with your desired reply-to name and email address.

Code Preview
php
<?php
/* Set a Custom Reply-To Email
 * 
 * Original doc: https://wpmailsmtp.com/docs/setting-a-custom-reply-to-email/
*/
function wp_mail_smtp_dev_reply_to( $args ) {
 
	$reply_to = 'Reply-To: Pattie Paloma <[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 );

Comments

Add a Comment