Send replies to WordPress emails to your support inbox, even when they're sent from a no-reply address.
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;
} );
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.
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.
support@example.com to your real inbox.wp_mail().Reset a test user’s password, then reply to the email. The reply should be addressed to your support inbox.