How to send Email from localhost using PHP

Hello Everyone,

in this tutorial i m exaplain in detail how to send email from your localhost. you might be wonder why mail function is not working from your localhost. i also faced the same problem whenever i have tried mail is sending it gives a error when run my mail script something like

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


Dont worry for this warning i m explaining if your mail function is not working on your localhost. folllow my below step.

  • open your php.ini file. Here i m explaining for XAMPP Server, it is located in c:\xampp\php\php.ini.(find out your xampp installed drive). and if you are using WAMPP server than find out.
  • in that php.ini file search [mail function] 

You can find find like

  •  in above code instead of localhost add your smtp server’s ISP. and no need to change smpt_port leave as it.
  • instead of postmaster@localhost add your domain email address which will be used as from address.
  • after changing for me it will be like this

  •  after changing once restart your WAMPP/XAMPP server so that changes will working after restarting.
  • and now run your mail functions script using mail() function

may be something like:

mail(“”,”Great”,”Thank you”,”Welcome to the”);

that’s all, now i m getting mail in from my localhost.

Cheers, Enjoy with Easy And Excellent Knowledge from