Send Emails from your Local WampServer Using PHP

So there you are, having churned out beautiful code for that amazing website or web application and you finally want to push it out. The interface is sleek, pixels are perfect, forms are usable and you love what you see. Now all that is left is to test if that sign-up email or newsletter or contact form auto-responder is working as you planned. Here you have two options, you could:

  1. Go through the gruesome and time-wasting process of uploading the site to your online testing server just so you can test a few forms (cursed be the times when your internet connection is down)
  2. Have faith in your coding skills and believe that everything is working perfectly. (Trust me, this never works → Murphy’s law)

I’ll give you a third option, one that I strongly advocate. Did you know that you could send mail straight from your local WampServer, with minimal configuration? The only problem is that WampServer does not come with a mail server. In this post, I’ll show you how we can get around that.

Step 1: Get all the ingredients ready

For this cool recipe, we’ll need a couple of things:

  1. WampServer — (rather obvious). As of writing this the latest version is 2.2a
  2. Byron Jones’ Fake Sendmail for Windows — Emulates sendmail to send emails through an SMTP server
  3. A domain with a personal email account — e.g. [email protected]

Step 2: Install WampServer

The WampServer installation should be straightforward. Install it with the default settings and it should go to c:wamp.

Next you should start WampServer and test that it is working by going to http://localhost in your browser. If you see the welcome page then you are good to go.

Step 3: Time for some sendmail magic

Now, a brief overview of Fake Sendmail. From the developer’s website:

sendmail.exe is a simple windows console application that emulates sendmail’s “-t” option to deliver emails piped via stdin….it requires an smtp server to perform the actual delivery of the messages.

In less tech speak, it emulates an email server to send and deliver emails. It however relies on an SMTP server to send the emails, and that is where your domain’s email address comes in.

To install Fake Sendmail, extract the sendmail.zip file that you had downloaded in step 1 above and place the extracted folder in c:wampsendmail. Next, open sendmail.ini in c:wampsendmail so that we can edit some configuration settings.

sendmail configuration

sendmail config

Step 4: Edit php.ini (It’s not as technical as it sounds)

PHP.ini is the mother configuration file for your PHP installation. It is very easy to edit, but take care to only change the lines below. Tinkering with the file unnecessarily could cause your installation to break. Do not fret though, all we are doing is telling PHP about our Sendmail magic.

Let’s dig in: go to C:wampbinphpphp5.3.5php.ini and open up php.ini in your favourite code editor. Do a quick search for “sendmail_path“, it should take you to around line 1094.

sendmail-config

All you have to do now is save and close php.ini and restart WampServer for the changes to take effect. And you are home free, that is all!

Please note: For all the files edited in Step 3 and Step 4, ensure you remove the leading semi-colon ;. The character is used to comment out files in the configuration files.

Now go forth and test away. I hope this will save you as much uploading time as it has for me.

The Caveat

I am primarily a Windows coder (yeah, I know…) so I haven’t tested this on MAMP or LAMP. In fact, I am a total douche when it comes to doing the above on a Mac or Linux machine. If you know a thing or two about that, drop your suggestions in the comments and I’ll update the article as appropriate.

signed. martians.™