Tinkerwell 4 is out now! Get the most popular PHP Scratchpad application. Learn more

Go back to Blog

How to use HELO with PHP's mail() function

Sebastian Schlein

This is a guest post by Marcus Bointon

HELO works very nicely if you're sending via SMTP using SwiftMailer, PHPMailer, etc. – but lots of apps and scripts rely on PHP's clunky old mail() function, which isn't nearly as easy to deal with, and harder to point at HELO.

You can configure "proper" mail servers like postfix to work as a local relay, but it's horribly complicated and confusing to set up. Fortunately there are simpler alternatives that are much easier. Searching for local relay tools (what this is) will usually point you at ssmtp, however, that doesn't work on macOS. A better option for macOS is msmtp which is present in homebrew and works perfectly. I usually run HELO on localhost port 2500, and I configure msmtp with a config file like this, which enables the authentication that HELO requires:

  • defaults
  • host localhost
  • port 2500
  • tls off
  • undisclosed_recipients off
  • account default
  • auth plain
  • user test
  • password password

To make the PHP mail function use msmtp, you need to configure the sendmail_path setting in your php.ini file to point at it:


sendmail_path = /usr/local/bin/msmtp -t -i

If you're using homebrew's PHP package on macOS, I recommend putting config changes like this in a separate .ini file so that it remains update-safe, for example I put mine in /usr/local/etc/php/7.4/conf.d/marcus.ini.

With those two things in place, PHP's mail function will submit to the local msmtp binary, which will then relay the message to HELO over SMTP.

Painless local email testing

HELO is a desktop application that will change the way you test your emails. No more broken links, missing images and customer complaints.

Learn more
Invoker screenshot