h1

Running PHP mail() in Your Local PC

May 29, 2009

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.

2

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

3

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).

5

6

7

8

9

10

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)’.

11

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

12

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

HTH :)

11 comments

  1. That’s an instant tutorial! Thanks.


  2. @lysender,

    you’re welcome :D

    jhoy


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


  4. thanks ate marian :)


  5. 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.


  6. try to run search in the folder where you installed XAMPP


  7. thanks mate, very usefull


  8. you’re welcome :D


  9. 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


  10. you’re welcome. :)


  11. 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?



Leave a Comment