Home / Admin / Fix the InvalidInternetMessageHeader Error in Outlook
Duplicate Snippet

Embed Snippet on Your Site

Fix the InvalidInternetMessageHeader Error in Outlook

This snippet will modify specific headers in your emails, which can help resolve this ‘InvalidInternetMessageHeader’ error exclusive to the Outlook mailer.

On line 12, you’ll need to replace 'Auto-Submitted'with the name of the header that’s causing the ‘InvalidInternetMessageHeader’ error in your setup.

Next, replace 'X-Auto-Submitted'on line 13 with the problematic header’s name prefixed with 'X-'. This means you’re renaming the original problematic header to a new one that adheres to the X- prefix standard.

Code Preview
php
<?php
/* Fix the InvalidInternetMessageHeader Error in Outlook  
 * 
 * Original doc: https://wpmailsmtp.com/docs/fixing-the-invalidinternetmessageheader-error-in-outlook/
*/
function wp_mail_smtp_modify_header( $body, $mailer ) {
	
if ( 'outlook' === $mailer ) {
	$headers = $body[ 'message' ][ 'internetMessageHeaders' ];
	
	foreach( $headers as $key => $header ) {
		if ( 'Auto-Submitted' === $header[ 'name' ] ) {
			$body[ 'message' ][ 'internetMessageHeaders' ][$key][ 'name' ] = 'X-Auto-Submitted';
		}
	}
}
	return $body;
}
add_filter( 'wp_mail_smtp_providers_mailer_get_body', 'wp_mail_smtp_modify_header', 10, 2 );

Comments

Add a Comment