Created
April 25, 2024 15:23
-
-
Save vkartk/45b20c750ef81d33454eec8b5bcc0113 to your computer and use it in GitHub Desktop.
Wordpress Custom Reply-To Email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sets reply-to if it doesn't exist already. | |
add_filter( 'wp_mail', 'wp_mail_filter_set_reply_to' ); | |
function wp_mail_filter_set_reply_to( $args ) { | |
if (!isset($args['headers'])) { | |
$args['headers'] = array(); | |
} | |
$headers_ser = serialize($args['headers']); | |
// Does it exist already? | |
if (stripos($headers_ser, 'Reply-To:') !== false) { | |
return $args; | |
} | |
$site_name = get_option('blogname'); | |
//$admin_email = get_option('admin_email'); | |
$support_email = sanitize_email('reply-email@domain.com'); | |
$reply_to_line = "Reply-To: $site_name <$support_email>"; | |
if (is_array($args['headers'])) { | |
$args['headers'][] = 'h:' . $reply_to_line; | |
$args['headers'][] = $reply_to_line . "\r\n"; | |
} else { | |
$args['headers'] .= 'h:' . $reply_to_line . "\r\n"; | |
$args['headers'] .= $reply_to_line . "\r\n"; | |
} | |
return $args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment