Setting a Custom Reply-To Email

Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy but don’t provide support for code customizations or 3rd party development.

Overview

Would you like to change the reply-to email address for all emails sent from your WordPress site? The reply-to email address can differ across each plugin or integration used to send emails from your site, depending on how you have each one configured.

In this tutorial, we’ll show you how to use a PHP snippet to ensure all emails sent from your site have the same reply-to email address.

Note: Be sure to install and activate the WP Mail SMTP plugin on your site before adding the code snippet provided in this tutorial.

Setup

We recommend that you copy and paste the required snippet below into a new WPCode snippet. WPCode makes it easy and safe to run code snippets on your site.

For help with adding snippets to your site, please see our tutorial on adding code snippets using the WPCode plugin.

Simply copy and paste this snippet into WPCode. On line 3, you’ll need to replace Pattie Paloma and [email protected] with your desired reply-to name and email address.

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 );

Note: The reply-to email address you use in this code snippet will overwrite all other reply-to addresses set by WordPress or 3rd party plugins.

That’s it! Now you know how to successfully change the reply-to email for all the emails sent from your WordPress site.

Next, want to explore more ways to customize your WP Mail SMTP setup? Be sure to take a look at our other code snippets for more customization options.