Sending mail from Localhost in XAMPP WAMPP using PHP

During Web Development in Windows environment, we use XAMPP/WAMP or some other local web server environment to test the code. In many cases includes the sending of mail, so it’s lazy job to upload the file in the server and test. In this case we can set the SMTP (Simple Mail Transfer Protocol) in our local server located in php.ini file.

In case of XAMPP, edit the file located in \xampp\php\php.ini

When  the SMTP is not set, error like this is displayed:

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\testmail.php  on line 10

Search for – [mail function] and change the SMTP value.

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25


Where domain – Domain name of your Internet Service Provider e.g.,,

In some case it may be –,

While sending  mail Headers  need to be defined to specify sender, content type etc.

$headers = "From:"."\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";

Now Restart the Apache and try sending the mail.

mail('','Testing mail','Mail received from localhost',$headers);
Be Sociable, Share!
You can leave a response, or trackback from your own site.

5 Responses to “Sending mail from Localhost in XAMPP WAMPP using PHP”

  1. subinmertz says:

    I’ve been using adsl(ntc) but by setting SMTP as or it didn’t work.

    • admin says:

      I have tried with NTC ADSL using, It works, May be you forgot to include header or made error somewhere. Follow the instructions once again.

  2. flavah says:

    I am trying to send mail to my mailing account through my website service form that i am hosting myself. My question to you is, what must i put has my SMTP name, should it be or

    NB- My hostname i receive is from and the index file to my website is on my server.

    Need your intervention ASAP. Thank you

    • admin says:

      If you are hosting on online server then you need not to set any SMTP, It is required only during testing the codes on local server i.e. from your computer.

  3. ramesh says:

    please tell how to solve the error
    mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for in C:\xampplite\htdocs\xampp\mail.php on line 34

Leave a Reply

CommentLuv badge

Powered by WordPress