How to set up SMTP server on Localhost-Configure php.ini

In this tutorial, I will explain how to set up SMTP server on Localhost and how to configure php.ini file.It is very easy to send Email from localhost.I was trying to send a mail via php mail function.The following error comes

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\php\send_email.php on line 11.


You need to configure php.ini file to send email via php send mail function.

1. Open php.ini file.

Default php.ini file settings

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

; For Win32 only.
sendmail_from = you@yourdomain

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

these entries are required to send the mail to any mail client from mail server.

2.The following two lines don't exist:


you need to add them to send mail from a server that requires authentication.

3. change SMTP settings

smtp_server = ///your SMTP server name.
smtp_port = 26 // SMTP port number
auth_username =
auth_password = password
sendmail_from = // from email address.

4.SAVE php.ini file.

5. Restart Server.

6. DONE.

It's working for me on WAMPSERVER.


$to = "";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "";
$headers = "From:" . $from;

if (mail($to,$subject,$message,$headers)) {
Message successfully sent!
  } else {
Message delivery failed...


I hope, this will help you to Send Email from Localhost.