Email PHP Beginner

Add a Reply-To Address to WordPress Emails

Send replies to WordPress emails to your support inbox, even when they're sent from a no-reply address.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 14 lines
add_filter( 'wp_mail', function ( array $args ): array {
	$headers = is_array( $args['headers'] ) ? $args['headers'] : array_filter( explode( "\n", str_replace( "\r\n", "\n", (string) $args['headers'] ) ) );

	foreach ( $headers as $header ) {
		if ( preg_match( '/^\s*reply-to\s*:/i', (string) $header ) ) {
			return $args; // Keep a Reply-To set by a plugin or form.
		}
	}

	$headers[]       = 'Reply-To: Support <support@example.com>';
	$args['headers'] = $headers;

	return $args;
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Many sites send email from an address like no-reply@yoursite.com for deliverability. When people hit Reply, their message disappears. Adding a Reply-To header sends replies somewhere useful.

How it works

The wp_mail filter changes every email’s settings before it’s sent. The snippet turns the headers into a list and adds Reply-To with your support address.

If an email already has a Reply-To, for example a contact form setting it to the visitor’s address, the snippet leaves it alone.

Things to watch

  • Change support@example.com to your real inbox.
  • Plugins that send email through their own API may not use wp_mail().

How to test it

Reset a test user’s password, then reply to the email. The reply should be addressed to your support inbox.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only