Friday, January 29, 2010

How to send mail from Localhost with XAMPP and mercury/32

Had tried to make php mail() work on localhost. But had failed. So gave up. This was around 8 months back. Now again some days back had to use the Php mail function on one project. This time I had the liberty to test my code on an external web server, but i tried again to make it work on my localhost.

A lot of google searching and some simple steps, I could make it work.So here sharing my experience with you. Hope this helps someone like me.

I use XAMPP as my local web server on my Windows machine. For php mail() function to work on the localhost, you need a SMTP mail server.


A Web server : Here we use the xampp package. You can download it from here. It is very easy to install and does not require any expertise.
A Mail server : Mercury/32 Mail Transport System is an excellent mail server bundled with XAMPP. So no need to search for any other mail server.
A Mail Client : You need to have a mail client to receive mails sent from localhost or basically from your Mercury/32 mail server. Mail clients include outlook express, thunderbird, Eudoramail etc. For this tutorial I will be using the default mail client available with Windows system , ie the outlook express.

The Steps to Configure Mercury/32 mail server

The following steps will guide you through the working of mail function on localhost.
1) You need to start the localhost web server. The XAMPP in this case.

2) By default XAMPP will not start the mercury mail server. So you need to click on start to start the mercury/32 on the XAMPP control panel.

3) Click on the Admin Button next to mercury on XAMPP control panel. This will open the Mercury/32 Admin Panel. Click on Configuration -> Manage Local users.

4) Create a New User. Let
Username : root
Password : root

5) Next, from the Mercury/32 Admin panel, Go to Configurations -> Mercury SMTP server and make the following Changes.
IP Interface to use :
Listen to TCP/IP port : 25
Announce Myself as :

6)Next, from the Mercury/32 Admin Panel , Go to Configurations -> Mercury POP 3 Server and fill in the following details.
Listen to TCP port : 110
IP Interface to use :

7) Next, from the Mercury/32 Admin Panel, Go to Configurations - > MercuryE SMTP client Configuration , and make the following changes
Identify Myself as :
Name server :

8) Next step is from the Mercury/32 panel go to Configuration -> Mercury D pop3 client and there create a new Account. Click on “ADD” and then enter the following details for “Edit POP3 mailbox definition” dialog box.
POP3 Host :
Username : root
Password : root
And then click on save.

This finishes Configuration of your Mercury/32 Mail transport system.

We now have to configure a mail client, so as to receive mails. We will use the windows default mail client, the outlook express. The following steps will guide you to create a user account on outlook express.

Steps to set up OUTLOOK EXPRESS

1)Open Outlook express and then click on Tools -> Accounts -> Add, and then click on Mail

2)For new Internet account on outlook express , create a new user
Enter display name: root

Enter email Id:

Then click Next. On the Internet Connection wizard,
Select POP3 for my incoming mail server.
For Incoming mail (POP3, IMAP, HTTP) server, enter
For Outgoing (SMTP) server, enter

Click on Next and then , enter the following fields
Account name : root
Password : root
Click on finish and you are ready to Go.

Once you have finished creating a account on Outlook express , send a test mail to yourself.

You can now test your php code to check if your script is working successfully or not.You can try this script. Copy the code and save it in a file for eg mail.php. Save this file in your root folder , for xampp it will be in your htdocs folder.

//php code to send mail,
//author : idrish laxmidhar
//Use this code to send a test mail from your localhost.

$to = "";
$subject = "Hi!";
$body.="Hello World. If all went well then you can see this mail in your Inbox".PHP_EOL;
$body.="Idrish Laxmidhar".PHP_EOL;

$headers = "From:";

if (mail($to, $subject, $body, $headers)) {
echo("Message successfully sent!

} else {
echo("Message delivery failed...


Run the script. If all went well, the script should execute successfully. Check your email. You should receive an e-mail.

Well this finishes the tutorial. Hope it helps someone out there.
P.S This is my first attempt to write a tutorial. your queries or Suggestions are highly appreciated. Thanks


  1. Good tutorial but the code section looks bigger and seems to need changes. It will be nicer if the screenshots look closer. Material is good. Congratz for your first ever tutorial.

  2. interesting.....!!
    Representation is nice & friendly. I will try with it. Carry on, maaan.

  3. Bravo Sir! I needed to test XAMPP's PHP mail and this explained very well how to configure Mercury.

    I used IncrediMail as a client and it was set up flawlessly.

    Thank you.

  4. that really worked! :) i wasted lots of time to find something useful until i find this - very useful work thank you :)

  5. Great tutorial - nice and simple.

  6. Step 5, there are multiple options for Mercurial SMTP server (ie MercuryS SMTP server). Care to elaborate?

  7. i have configured everything, how you have explained above,also it displays email sent successfully.but when i check my outlook inbox it is empty.and i am not able to sent in other emails also.what is the problem in my settings?

    1. Try clicking on the "Send/Receive" button on MS should be just below your menus....

  8. Bravo bravo! Ngyabonga kakhulu ingisizile...kudala ngicingana nalento ngingazi ukuthi ngizoyithola kuphi nakanjani. ngyabonga mfwethu!

  9. How if i want to send out to yahoo mail or gmail?
    would it still be work?

    i follow those step to set up the SMTP server but still cant send out email to my yahoo mail nor gmail

  10. why i am not able to send email to any other domain like gmail or yahoo?

  11. Thanks for the great tutorial.
    I got a problem I can send a email from AccountA@localhost to AccountB@localhost. But I can't send mail to my gmail account from either AccountA@localhost OR AccountB@localhost.
    Please kindly advice. Many thanks!

  12. Do I have to set up Outlook Express? I only use hotmail and I can't find out where to add the new user..

  13. thanks.

  14. Good tutorial, had no idea what it was you had me do, but it worked... well almost.

    If you follow this tut, and end up with a failed delivery and the response...
    "SMTP server response: 421 Service not available"

    Check this for this directory > "C:\xampp\MercuryMail\QUEUE"

    Assuming you're xampp install is on C:

    My xampp install never created this directory, if yours is missing after that error, simply create the directory and viola

    Thanks for the tut

  15. I am not receiving email in outlook using php script.please help me...

  16. Your blog is really one amongst my most favorite blogs, it’s so creative.

  17. pls help sir my xampp or outlook work properly but mail not received

  18. Hello, According to Mercury32 i can execute the scripts and they work but the smtp client (outlook) is not receiving the messages. Do you know what could cause this? I can see the message on the smtp server and everything is going smooth except the outlook client. Please help i really need this soon.

  19. The above did not work for me UNTIL I commented out the following line in my php.ini file:
    sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe". By default, this is enabled in XAMPP v5.6.8.

    1. thanks a lot, you saved my day.

    2. Thanks, that helped me too. Dzięki!

  20. Hello, I have set up mercury to how you said to in you online tutorial it all seems to work when I send am email though outlook using my ,Mercury receives it then send it on. I did also test it though mercury internal mail centre and work there, but when I go and send a php form the form looks to or send and I get me conformation page say it does I looking in outlook no email. Nothing in junk/spam mail, I look in the Mercury the pop serve tell me no message or mail has been received.

  21. Its not working for out mailing i mean like gmail or hotmail.

  22. Its not working for out mailing i mean like gmail or hotmail.

  23. Thank you for the information, I think this article is very useful for all who read it.
    Daftar Yahoo Mail

  24. Goodmorning, i'm using thunderbird instead of outlook, how can i force woocommerce to send emails on my localhost email adress, when product order changes status to complited? I can't force woocommerce to use my new local adress ;/

  25. thank you very's helpful for me...

  26. This comment has been removed by the author.

  27. Than you very much, It helped me fixing my problem as well as learning a lot of stuff !!!