Development Environment Help! Setting Up PHP mail() On Windows, Or: Where Is My Windows sendmail.exe?

Lately at work I’ve been having the worst of trouble getting PHP on my workstation to send mail. Previously it was a simple trek to a website to download a Windows build of sendmail.exe, but for some reason I cannot get access to it, so I have to go another route.

Enter hMailServer, a free, full-featured SMTP/POP/IMAP server for Windows with a pretty, shiny GUI configuration interface. All I really want to do is setup SMTP for localhost only but one could easily use hMailServer as a production mail server.

To start things off, lets make sure our php.ini directives are setup correctly. By correct, I mean PHP needs to be looking for our SMTP server on my local machine (localhost) at the default SMTP port (25), and, just in case, set a default from address:

[mail function]
; For Win32 only.
smtp = localhost
smtp_port = 25

; For Win32 only.
sendmail_from = user@domain.tld

Looks good. Second step is to download and install hMailServer. This tutorial is working from version 5.2 build 356, but you should be able to use the latest stable or unstable version that you might desire.

Once you’re installed and configured, run the administrative application. If you click over to status you will notice a message to the effect of “You haven’t specified the public host name for this computer in the SMTP settings.” That means we have some more configuration to do!

hMailServer Screenshot 1

Now mosey on over to Settings » Protocols » SMTP, navigate to the “Delivery of e-mail” tab. We set our “Local host name” to “localhost” and click “Save”.

hMailServer Screenshot 2

Next, for securities sake (as well as to ensure we don’t have to waste time configuring account as this is only a dev machine), go to Settings » Advanced » IP Ranges » My Computer. Un-check the POP3 and IMAP checkboxes under the “Allow Connections” as we don’t intend to receive mail, nor use the IMAP protocol. Then, un-check everything under “Requires SMTP authentication” as we want our PHP applications to have full reign. Finally, click “Save”. Remember, this is a dev box.

hMailServer Screenshot 3

UNDER NO CIRCUMSTANCES SHOULD YOU USE THESE SETTINGS ON A BOX THAT WILL BE EXPOSING ITSELF TO THE INTERNET OR ON A PRODUCTION SERVER! However, since our local machine will obviously have internet connectivity, lets remove all access from outsiders!

Navigate to Settings » Advanced » IP Ranges » Internet. Un-check EVERYTHING from “Allow connections” to deny outsiders any services, and, just in case, check EVERYTHING under “Require SMTP authentication” and click “Save”.

hMailServer Screenshot 4

And voilà! We have a fully functioning SMTP server that our local PHP environment can use to send test email messages.

The nice thing about our administrative interface is if we go to Status, navigate to the “Logging” tab, and click “Start,” we can capture the dialogue between hMailServer and your PHP app when sending an email address (very useful for debugging).

Comments 4

  1. Eder Araujo de Souza wrote:

    I will test, needed something a while ago and had not found.

    Thanks for post!!!

    Att,
    Eder

    Posted 21 Aug 2009 at 1:59 pm
  2. Alejandro wrote:

    This is very useful, thanks

    Posted 21 Aug 2009 at 4:44 pm
  3. Charles Krause wrote:

    I understand that your post is an evaluation/tutorial of hMailServer – but as to the lack of a Windows sendmail, I’ve also considered using the Google Gmail API.

    Not as flexible or robust a solution but handy for offloading the heavy lifting elsewhere if your email needs are light.

    Posted 23 Aug 2009 at 6:55 am
  4. Daniel Cousineau wrote:

    Going the SMTP through Gmail route is perfectly valid. I prefer to do local SMTP servers on my development machine as it’s easier for me to debug issues (checking SMTP logs, viewing outgoing message headers) and let through … unsavory seeming email (namely dev box sending emails from live domain, despite the box it’s sending from is in no way associated with the domain).

    Posted 23 Aug 2009 at 7:21 pm

Trackbacks & Pingbacks 3

  1. From Daniel Cousineau’s Blog: Setting Up Mail() on Windows, or: Where is my Windows Sendmail.exe? | Webs Developer on 21 Aug 2009 at 1:00 pm

    [...] emails from his local machine from his PHP scripts. Thankfully he’s found a solution and has shared it in a new blog post. Previously it was a simple trek to a website to download a Windows build of sendmail.exe, but [...]

  2. From Daniel Cousineau’s Blog: Setting Up Mail() on Windows, or: Where is my Windows Sendmail.exe? | PHP on 21 Aug 2009 at 7:06 pm

    [...] emails from his local machine from his PHP scripts. Thankfully he’s found a solution and has shared it in a new blog post. Previously it was a simple trek to a website to download a Windows build of sendmail.exe, but [...]

  3. From WAMP – Windows – mail smtp strežnik – pošiljanje epošte | T&R splet - internetne storitve on 25 Feb 2010 at 4:38 am

    [...] Najbolj neodvisna rešitev je seveda postavitev lokalnega strežnika. Na voljo imam najbolj preprosti program Free SMTP Server ali hMailServer. Za enostavno testiranje priporočam FREE SMTP Server, za bolj napredno uporabo pa hMailServer. Postopek kako zadevo namestiti na Windows računalniku. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *