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.

  • Good stuff. I’ll check if Mac needs a workaround too…

    • Thanks. I’d love to see how it works on a Mac. I’ll also check how it works on Linux, though I think it comes with a mail server by default.

      • Just confirmed, on Mac the mail is sent without any extra settings. Told ya, worth every penny! Cross over, dude! :D

        • Aleena Grace

          Can any one help me?
          My email() is not working
          Mail is not sent . I tried all changes

  • Jan

    Just what I needed !!!! Thnx

  • Pingback: 7 Lessons Learnt While Building Zuqka.com | Skyline Design()

  • Emre
  • visitor

    hi, did all the settings but the mail is not dropping in my box! please what am i doing wrong?

  • Giovani Civico

    Thanks a lot for this tips…

  • Annette

    Hi,
    thank you so much. I tried to work this out for 2 days now following all kinds of advice on the internet. Now I found your way to do it and I can’t believe it: IT WORKS! The difference your explanations make is: you show exactly where to change the ini-files and that you have to restart the wamp server. I’m only new to php – so for me this was PERFECT!

    • Thanks for the kind words Annette. Am glad this helped

  • this is just NOOOOOMAAA

  • Bear

    Hey, how i wish i saw this post earlier! Damn! I wasted a good 1 week trying to configure my php.ini file and i realise what’s the mistake i’ve made only after i found you! Thanks man!

    Just to share, i’m using WAMP server 2.2 which comes with php version 5.4.3 and i made changes to the php.ini file by selecting the file by clicking on the wamp server icon on my tray. NO! DO NOT AMEND THRU’ THAT PATH! It’s different from the php.ini as in your C:wampbinphpphp5.4.3php.ini

    Maybe some of u guys made the same mistake as me.

  • syntax

    Black (african) coders o_O

    I thought I was alone

  • binal

    i try all steps the output is only email sending failed

  • binal

    plz help me how i solve it my putput is email sending fail..
    i use apache 2.2.11 and php 5.3

  • ragz

    its displaying success mssage but i cant find mail in my gmail…
    can any1 help me plz?

    • What about in the Spam/Junk folder?

    • mudasssir

      add me on facebook i will send you all the snapshot how u can send email i do this lakh times tell me what is the problem

  • enkeleasi

    Great tutorial. It worked like charm. You need to add a slash when you define the folders, that gave me hard time :) Instead of c:wampsendmail should be c:wampsendmail. The other thing is gmail uses TLS and port should be 587. On my gmail account I left IMAP only enabled and it worked. Thank you

  • khaled

    what do you mean by “change this to your domain” ? , what is my domain , what if i dont have one , sorry if i seem stupid :( ?

  • mudassit

    plz send me i want optionally send email using my gmail and yahoo mail how i hv to configure this on wamp server

  • mudassir

    like i receive email in yahoo account but i want to reply from gmail account how can i configure both in wamp server php.ini for opptionally sending email from gmail or yahoomail

  • SamKIvu

    Why do I keep getting this? Warning: mail(): Failed to connect to mailserver at
    "localhost" port 25, verify your
    "SMTP" and "smtp_port" setting in
    php.ini or use ini_set() in C:wampwwwscriptssendmail.php on line 2

signed. martians.™