Home / Admin / Set a Custom Email Header
Duplicate Snippet

Embed Snippet on Your Site

Set a Custom Email Header

This snippet sets custom email headers to ensure you can control specific behaviors of your sent emails.

To add a custom header, replace 'X-Custom-Header: header_value' on line 11 with the header name followed by a separator and then the header value.

Code Preview
/* Set a Custom Email Header
 * Original doc: https://wpmailsmtp.com/docs/setting-a-custom-email-header/
function wpmsmtp_custom_mail_header( $args ) {
	if ( ! is_array( $args[ 'headers' ] ) ) {
		$args[ 'headers' ] = explode( "\n", str_replace( "\r\n", "\n", $args[ 'headers' ] ) );
	$args[ 'headers' ][] = 'X-Custom-Header: header_value';
	return $args;
add_filter ( 'wp_mail', 'wpmsmtp_custom_mail_header');


Add a Comment