Skip to content

Instantly share code, notes, and snippets.

@vkartk
Created April 25, 2024 15:23
Show Gist options
  • Save vkartk/45b20c750ef81d33454eec8b5bcc0113 to your computer and use it in GitHub Desktop.
Save vkartk/45b20c750ef81d33454eec8b5bcc0113 to your computer and use it in GitHub Desktop.
Wordpress Custom Reply-To Email
// 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