How to send emails using your localhost wamp, mamp, or xampp

As a web developer many of us love to develop websites using a local server like wamp(Windows, Apache, Mysql, PHP), mamp(Mac, Apache, Mysql, PHP), or xampp(X (any of the four different operating systems), Apache, MySQL, PHP and Perl). Developing on a local server is very beneficial because you can change code without using the file manager or ftp and it is great for testing and debugging. Well if you’re like me I know you have ran into the sending a email using a localhost problem. In today’s post I will tell you guys how you can properly send an email using your localhost and hopefully saves you the headache.

Change your PHP.INI file

Open up your php.ini file and search for these lines of code. They should all be around each other.

Change the follow code to match your current settings. I have tried this method using google smtp and windows live and did not have any luck but it could be different for you. If you have your own website and hosting go to your cpanel>>Email Accounts>>More>>Config Email Client and copy your mail settings. The settings you want to copy are incoming mail server and port number for that mail server.

After you have successfully changed those line s of code in your php.ini file you must restart your local server to see the changes. I hope this had helped you solve your localhost mail issues and if you have any questions feel free to leave it below and I will be sure to answer you.

Joe Granados the author

Joe Granados is the owner of WebDevTuts. He is also a web designer & developer who loves to design and develop websites. If you're looking for him you can find him via @webdevtuts
  1. J Burke says:

    Great tip sir! Hopefully this fixes the issue I’ve had forever with WAMP… it’ll be nice to test all the mail functions in my Drupal and WordPress installs without a development server elsewhere!

  2. Malky says:

    Hi Marcel, this doesn’t work for me, but looking at the settings on my host, incoming mail is POP3 etc. No mention of SMTP is here except for outgoing email. Just for information in case any of your readers come across the same problem. Unless you know of any way around it?

    Great post though, thanks for that, I can maybe pass it onto others.


    • Marcell says:

      you can use pop3 also. If you have your own host this should work. I had no luck with google, live, yahoo etc only with my personal domain

  3. gursahib says:

    Marcell Sir,
    please help me with this email service!
    i too wish to send an email through a localhost to some non-local such as gmail or yahoo!
    here i did not understand the concept of domain! 😐
    what domain sir???
    how can i have a domain for myself! i work on a LAN! here domain means my IPaddress or what?
    what do i have to specify there?
    kindly give an example
    please.! i desperately want to work this for me.
    Thank You.!

    • By domain I mean your personal domain to your website. For example my domain name would be You have to create an email using your domain account and of course you will need hosting in order for it to work.

  4. gursahib says:

    got it sir!
    means i have to buy a domain for myself! 😐
    and that domain will act as a smtp server..
    please correct me! if am wrong!!
    and aren’t there any free web sites
    i googled few but dint succeed.!
    thank you sir.

  5. Srinivasu says:

    I’ve configured the above code for my local host “” file. But, still I’m not able to send the mail’s. The error message it reflected when failed to send mail is :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:\wamp\www\mail\contact.php on line 1,

    Please help me in this scenario

  6. jacklyn says:

    hi, i using wamp server. I want to send mail from localhost to web mail server like gmail, hotmail etc…how to do that? Is it i need to install mail server into my pc? how to configure it?

    • I am not sure if gmail or hotmail works with localhost. I have tried both and had no luck but using my own web server I was able to get it to send emails.

  7. jacklyn says:

    this is the module i want to apply into my web. But i fail the configure the email part and oways get tis error “Warning: mail() [function.mail]: Failed to connect to mailserver at “” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\wamp\www\Registration_system_with_Email_Activation\index.php on line 69″…

    can teach me how to solve this?

  8. Hannibal says:

    Hi Marcel. Thanks for the helpful post. I am trying to send mail from an apache2 localhost on Ubuntu. The mail function returns true but I don’t actually receive the email when I check my Gmail. I installed postfix and php5 could you point out what changes I should make to the configuration you originally posted?

  9. Priyanka says:

    I have to send mail to gmail from local site.But it will be send by admin mail id which will be some company employee email id.
    What should i have to do???

    • Ive tried google and had no luck. Do you have a cheap hosting account? You can get it then use the email feature and have gmail forward your email from your web server to gmail. I hope that makes sense.

  10. Priyanka says:

    Thanks for reply…
    Actually I have intranet site…in that one survey module..after completing survey i have to send notification to admin…
    Can you help me for it??

Leave a Reply