PHP cannot perform SMTP authentication natively using the mail() function. The way I set up my development server is to allow unauthenticated SMTP emails to be sent from the PHP webhost IP address on a non-standard port
Creating a Webhost SMTP Account
- Open the Start Menu > hMailServer > hMailServer Administrator
- Select localhost > Click Connect
- Login with the password set during the installation
- Expand Settings > Advanced > IP Ranges
- Click the Add... button
- Enter PHP Webserver as the Name, set I priority above 50 and enter the PHP Webserver IP in the Lower and Upper IP address fields
- Uncheck POP3 and IMAP from the Allow connections options
- Uncheck Require SSL/TLS for authentication
- Uncheck all boxes under Require SMTP authentication
- Click the Save button
- Expand Settings > Advanced > TCP/IP Ports
- Click the Add... button
- Select SMTP from the Protocol dropdown
- Enter a non-standard SMTP port (8025) for PHP to communicate on
- Set Connection security to None
- Click the Save button
- Click Yes to restart the hMailServer service
Configuring PHP SMTP Server
- Navigate to the PHP installation directory and open php.ini in a text editor
- Search for SMTP
- Update the following parameters
SMTP = smtp.i12bretro.local
smtp_port = 8025
Optionally, set the mail.log to a file path for logging or syslog to log to the event viewer- NOTE: If using SSL the certificate authority needs to be trusted by PHP. This can be setup by adding the CA and intermediate CA certs to a .pem file and setting the curl.cainfo value in php.ini
- Select File > Save
- Restart the Apache or IIS service
Testing PHP Mail() Call
- Open a text editor
- Create a PHP file with the following code