Using the wp_mail
filter I add a "Reply-To" to the header with my email address, so clients can reply directly to the email to contact me if there's any issues. I only want this on WordPress "system" emails, like emails for new accounts, password resets, etc. If a plugin sends an email using wp_mail()
I don't want to set the Reply To address. Is there some way to know when it's WordPress core sending an email rather than a plugin?
Here's what I'm using to set the Reply-To (from a custom class):
public function __construct() {
add_filter( 'wp_mail', array( $this, 'setReplyTo' ), PHP_INT_MAX );
}
public function setReplyTo( array $args ) : array
{
$reply_to = 'Reply-To: My Name <[email protected]>';
if ( ! empty( $args['headers'] ) ) {
if ( ! is_array( $args['headers'] ) ) {
$args['headers'] = array_filter( explode( "\n", str_replace( "\r\n", "\n", $args['headers'] ) ) );
}
// Remove existing 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;
}
Nothing in the $args
parameter appears to contains anything I can use to accomplish this. Hopefully there's some way to know what is initiating the emails. Thanks!