# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Email](https://wpide.com/library/category/email/)
- Tags: email, reply-to, routing
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-reply-to-rules/

## Code

```php
// Text found in the subject (case-insensitive) => Reply-To address.
$wpide_reply_rules = array(
    // 'order'   => 'orders@yourdomain.com',
    // 'support' => 'support@yourdomain.com',
);

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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Reply-To Address Rules by Email Subject" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
