Using the mail() function with HELO in Windows

14th Oct 2020

php

NOTE: This is based on the excellent guest post on the HELO blog, however this is not supported in Windows.

For some of my legacy projects, they are still using the mail() function rather than a package such as SwiftMailer, so on Windows these can't be configured using the common SSMTP or MSMTP packages (as suggested in the HELO blog).

To get started, install Sendmail for Windows, for example through Scoop:

scoop install sendmail

In your Sendmail configuration (e.g. ~/scoop/persist/sendmail/sendmail.ini), update the Sendmail configuration to use HELO's connection settings:

[sendmail]
smtp_server = 127.0.0.1
smtp_port = 2525
smtp_ssl = none

; Auth (username will be the mailbox name)
auth_username = HELO
auth_password =

In your PHP configuration (e.g. ~/scoop/persist/php/cli/conf.d/sendmail.ini) add the following (replacing your username in the path):

; Absolute path to the Sendmail executable
sendmail_path = c:/users/[username]/scoop/apps/sendmail/current/sendmail.exe

You should now be able to open HELO and send an example email using:

php -r "mail('[email protected]', 'Test', 'Test with HELO', 'From: Test <[email protected]>');"

NOTE: I've experienced some issues with HELO on Windows where the SMTP server continues to run in the background when HELO has been closed. You may need to force close the application.