Reply-To Address Rules by Email Subject
Sets a different Reply-To address depending on the email's subject, so replies to order, support or form emails reach the right team automatically.
Opens WPIDE on
Code
// Text found in the subject (case-insensitive) => Reply-To address.
$wpide_reply_rules = array(
// 'order' => '[email protected]',
// 'support' => '[email protected]',
);
add_filter( 'wp_mail', function ( $atts ) use ( $wpide_reply_rules ) {
$headers = is_array( $atts['headers'] ) ? implode( "\n", $atts['headers'] ) : (string) $atts['headers'];
if ( false !== stripos( $headers, 'Reply-To:' ) ) {
return $atts;
}
foreach ( $wpide_reply_rules as $needle => $address ) {
if ( false !== stripos( (string) $atts['subject'], $needle ) && is_email( $address ) ) {
if ( is_array( $atts['headers'] ) ) {
$atts['headers'][] = 'Reply-To: ' . $address;
} else {
$atts['headers'] = trim( $headers . "\nReply-To: " . $address );
}
break;
}
}
return $atts;
} );
Notes
Add your subject-to-address rules at the top (the first match wins); emails that already have a Reply-To are left alone.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.