Thursday, January 28

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

Be the first one to Comment!!!

  1. Hey nice tutorials ha..gud work idru

  2. Thanks for the tutorial. I've been having some trouble sending mail the past few month, but this tutorial has helped tremendously.

  3. @peter : You are welcome. I am glad that this tutorial helped you.

  4. Hey man, thanks for the tut. Unfortunately everytime I try to send an email MERCURY CORE PROCESS doesn't finish the job (job pending).
    At the same time Mercury SMTP CLIENT displays this message:

    Temporary error 249 (temporary MX resolution error) resolving ''.

    Any idea what's that about?
    Many thanks

  5. Hi xyyp.
    May be you could try with localhost instead of while configuring you mail server. This might help.

  6. Wow you're brilliant!!! Couldn't find this anywhere else on the web...
    But I have one problem... With your set up I have tried to send an email to one of my gmail addresses however it says 'Temporary error 249 (temporary MX resolution error) resolving '' on the SMTP client, do you know what I'm doing wrong???



  7. Hi will.
    I have in this tutorial tried to achieve how to send and receive mails from localhost, when you do not have a external web server. However here is a link which might help you.

    Thanks for your comment.

  8. Great Tutorial! However, I do have one small problem, when I run your mail script, it shows that everything was a success but, when I go to check in outlook (where I created the root account) it says that my password is incorrect and it cannot send or receive any emails for localhost(root) ??? any suggestions?

  9. @Nic. Hey nic, thanks for your comment. However about your problem, i think you should create another account on your outlook express and try again. Nothing else, that i can think of. Hope your problem gets solved. Thanks

  10. Thank you for this great simple usefull help

  11. This does not work - generates No Socket Error in Outlook express and also requires modifications to the php.ini files which are not mentioned here

  12. HI J, I have tested it myself and it works for me. The screenshots above show that it worked for me in mozilla thunderbird. If you could give me more details about what error you get, then we can find a solution for it. Also it would be great if you could tell us more about php.ini file modifications. I shall cross check it and update the blog if required. thanks for your suggestions.

  13. Hi im having problems trying to send a test mail to myself. I have done every step that is stated but am still facing problems. Help please

  14. For linux users, you can use msmtp.
    You can see the tutorial here:

  15. hi,

    Please Help anybody. I followed your instructions to the point. However i am unable to connect to mercury by either using thunderbird 3.1 or outlook express 2007...

  16. For me outlook files are very important, but once something happened with my account. I was upset, but could enter the Inet and absolutely by chance retrieved there - .pst password recovery tools. It was perfect and solved my problem for seconds. I suggested it some of my friends and one of them thanked me a lot.

  17. @t0x1caT0r Hi. Thanks for the link. Now we are planning to shift to LAMP and it will help a lot. Thanks once again

  18. @Alex : Thanks a lot for the tip. Have been using outlook for some time now.

  19. Mercury can send e-mail to

  20. I tried this, but it didn't work as supplied. However, changing the email address to "root@localhost" (i.e. losing the ".com") did work.

  21. the php code is works: "Messages successfully sent!" but i'm not receive the messages in my outlook express. i got an error messages while i'm trying to connect to the server with outlook express. it says: "The connection to the server has failed. Account: 'localhost', Server: 'localhost', Protocol: SMTP, Port: 25, Secure(SSL): No, Socket Error: 10061, Error Number: 0x800CCC0E. I did follow all steps above, but it didn't works. can someone help me. i need to test receive and send email from localhost. thanks for any help :D

  22. Thanks! It was very useful for me and my tests in localhost with a newsletter system! :)

  23. thanks bro !!!!!!!!!!!!!!!!!!!!!!

    this tutorial is too good it solve my problem because
    in windows 7 i am not able to see the help and your tutorial help me lot

    GUYS ITS WORK !!!!!!!!!!!!!!!!!!!

  24. Hey Man,

    Your tutorial here is superbly amazing!

    I had to setup a local SMTP server for my assignment and i did everything u said here and everything works.

    everytime i try to send a mail via the php mail function to a non-local address, like etc,

    i get that temporary error 249 message.

    any way i can get it to pass?

    My assignment is to send user's password to the user's specified email address.

    sending to root@localhost works,
    but others ain't going

    any way?

    PS: i wasn't taught this but am trying...

  25. hi all, I had the same problems and was able to get things working for localhost testing by going to Configuration> Mercury core module ..., then under local domains tab I added as a new internet name and under localhost or server

  26. Every time I use ms outlook. I opened and tried to receive new email but couldn't. As it turned out it was unknown problem. Only next tool could solve it. I was lucky when I found out it at one soft blog. The application finished my troubles for some minutes and would become good decision for any problem with ms outlook - ost recover.

  27. Thanks for the tutorial. Very straightforward and understandable.


    Ramon M.

  28. Log onto incoming mail server (POP3): Outlook cannot connect to your incoming (POP3) e-mail server. If you continue to receive this message, contact your server administrator or Internet service provider (ISP).

  29. its showing the following error:
    Warning: mail() [function.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:\xampp\htdocs\xampp\mail.php on line 12
    Message delivery failed...

  30. my php code works "message sent successfully" but i dont receive mail in my outlook inbox however when test mail from mercury server is sent, i receive mails in outlook inbox this means mercury is working and mercury & outlook are in tune but when i try to send mail from php code it says its done but no mails are received in outlook what went wrong here please help

  31. is there any tut show how to set up mail that able to send to external email address?

  32. Dear sir,
    i receive mail in outlook express, but when i send it from php code it is not receive...