How to disable the X-Mailer header with PHPMailer

Josh Sherman
1 min read
Software Development PHP

Sometimes things aren’t quite as you’d expect them to be. One such case is when you try to disable the X-Mailer header with the PHPMailer library.

The library itself is pretty straight forward, you instantiate the class, and then you can interact with headers as object properties as such:

$mailer = new PHPMailer();
$mailer->XMailer = 'My Awesome Script';

Great, but what if you wanted to disable it completely? My first thoughts would be to set it to an empty string or false:

$mailer->XMailer = false;
$mailer->XMailer = '';

Turns out, both of those retain the original X-Mailer value. The proper way to disable the X-Mailer, historically has been to set it to a string with a single space:

$mailer->XMailer = ' ';

I say “historically” because it seems that more recent versions worked through some issues with PHP and fixed things up to support null as well:

$mailer->XMailer = null;
Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles