Running PHP mail() in Your Local PC

Posted on Updated on

Email testing has been a headache for most developers. You need to upload your script every now and then just to check if your script is working. A tedious work especially when you got a bunch of email script to work on. It would have been very nice if you could do it locally in your pc.

XAMPP provided an email server to PHP developers that would help ease our suffering. Mercury is a pre-installed mail server in the XAMPP that only a few knows how to use. I am one of the many that don’t until recently, I needed to test a lot of email scripts and frequent uploading is oftentimes vexing.

I have found a good thread that helped me in setting up the mail server in my computer.

In this tutorial, we will be needing XAMPP bundle (I am using version 1.7.0) and Thunderbird as our email manager. I will be assuming that you have successfully installed both softwares in your computer.

Running Mercury and Apache Server

Open your XAMPP Control Panel(CP) (Start > Apache Friends >XAMPP Control Panel) and make sure that Mercury mail and Apache is running. If not simply click the ‘Start’ button beside them.

XAMPP Control Panel Application

Email Accounts

In the XAMPP CP, open the Admin area of Mercury by clicking the corresponding admin button. Warning: Do not close any of the window inside the admin area.


In the admin area, go to Configuration > Manage Local User. In here, we could set the admin password and create new user.


To add admin password, select admin then hit ‘Change’. Fill-up ‘Mail Password’ then ‘Ok’.
To add new user, click ‘Add’ then enter username and password for the user.

Remember: the username is used as the email address. Example: Username=admin, Email=admin@localhost

Here, I created useraccount ‘jane’, so her email will be ‘jane@localhost’. We use ‘localhost’ because we are running  our mail server in our localhost.

Default ‘From’ Email address

To set our default email address, open file ‘XAMPP\apache\bin\php.ini’. Warning: If you are not familiar with php.ini file, it is best that you a save copy of the file before commiting any changes to it.

Search for ‘;sendmail_from’ and change this line to ‘sendmail_from = admin@localhost’ then save. We must now restart our Apache server.

Configuring Thunderbird

After setting up our mail server, let us now configure our Thunderbird so that we could read the emails that we would be sending in our localhost.

Open up the Thunderbird browser. Go to Tools > Account Settings. In the new window, Click ‘Add Account’ then follow the steps from the images below. Create an account for admin@localhost and jane@localhost (or whichever user account you created).







Testing Email Script

In your ‘XAMPP\htdocs’ create a folder named test. Inside ‘test’ folder, create an email script similar to the one below then save it as ’emailtest.php’. Run your script in your browser. ‘http://localhost/test/emailtest.php’. The output should be ‘bool(true)’.


Open your Thunderbird browser then click ‘Get Mail’. Enter the corresponding passwords once the prompt box appear.

The output should be similar to the one below


And there you go. You can now run your email script in your local pc.



15 thoughts on “Running PHP mail() in Your Local PC

    Lysender said:
    May 29, 2009 at 8:48 AM

    That’s an instant tutorial! Thanks.

    jhOy imPeRiaL responded:
    May 29, 2009 at 9:42 AM


    you’re welcome 😀


    marian said:
    May 29, 2009 at 7:20 PM

    thanks jhoy, very useful and informative!
    problem ko rin yan dati so I still have to upload the script from time to time.

    jhOy imPeRiaL responded:
    May 30, 2009 at 1:48 AM

    thanks ate marian 🙂

    bogdan said:
    June 13, 2009 at 5:40 PM

    I don’t know why, but I cannot find ‘XAMPP\apache\bin\php.ini’, where to fiind the file? in bin folder doesn’t exist.

    jhOy imPeRiaL responded:
    June 17, 2009 at 10:21 AM

    try to run search in the folder where you installed XAMPP

    tali said:
    July 10, 2009 at 8:51 PM

    thanks mate, very usefull

    jhOy imPeRiaL responded:
    July 11, 2009 at 1:31 AM

    you’re welcome 😀

    scaryhunter said:
    August 29, 2009 at 9:41 PM

    Thank you so much for the nice tutorial.
    I spent a week inorder to send a simple PHP mail text..Now with XAMPP and your awesome info it helped me alot.

    Thank you

    jhOy imPeRiaL responded:
    August 30, 2009 at 12:32 AM

    you’re welcome. 🙂

    NewGuy said:
    December 2, 2009 at 8:22 AM

    Hi, sorry but I am completely new at this … just starting with Javascript & hoping to progress to PHP later on. I am currently seeing forms in Javascript and got curious on installing Apache (locally, no internet) to test feedback forms and send them to myself or, if possible, to a gmail account. Is this possible?

    mes said:
    November 19, 2011 at 8:55 AM

    i got the problem with this,,pls help me
    Warning: mail() expects at least 3 parameters, 2 given in C:\xampp\htdocs\test\emailtest.php on line 4

    jhOy imPeRiaL responded:
    November 20, 2011 at 5:06 AM

    the basic is mail($to_email, $subject,$message);


    Nelson Rodrigues said:
    February 9, 2012 at 1:10 AM

    Thank you very much for this tutorial. Now I’m able to test my applications locally! 😀

    vikas said:
    June 27, 2012 at 1:15 AM

    Nice article. You can find the simplest way to use mail() in php from

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s