Using PHP mail function with locked-down SMTP server
I host my own Exchange server and had accepted the restriction that I couldn’t use the PHP mail() function thinking it was an incompatibility with IIS. It turns out, however, that my Exchange server (like most Exchange servers) requires a username and password to work.
I found a user on a forum that solved this problem so that he could use Gmail or an external SMTP Server that required SSL, and he wrote this up in a terrific article describing all the gory details.
Once I downloaded the package from the article, I made the following changes to the sendmail.ini file:
- Set
smtp_serverto point to my server. - Set the
smtp_portback to 25 (it was set to 587 to work with Gmail). - Set
default_domainfor addresses that don’t specify it. - Set
auth_usernameandauth_passwordto a valid email address and the password for that email address - this is the key right here that makes it all work. - Commented out
force_sender. I don’t want it always coming from a single username since I host multiple sites managed by different users.
Then I had to change my php.ini file. I commented out everything but sendmail_path. I tested this and it works great.
Note that the original author of the fake sendmail (Byron Jones) has released bug fixes, so you may want to download his later versions instead.
Resources
- Configure PHP under Windows to use Gmail or External SMTP Server [SSL]
- fake sendmail for windows by Byron Jones




July 7th, 2009 at 7:38 pm
Heh, I hit this problem with the built-in php mail() function a while back. Lo and behold, it didn’t support SMTP AUTH. Anyway I solved it, for plain, SSL and TLS mail systems using a library calss called mMail:
http://www.hotscripts.com/listing/mmail-php-class/
Worked well for me and was easy to work with.
Cheers!