How to send mail using PHP from localhost

In this article we will learn how to send email using PHP and MySQL from localhost.

Now follow all the below steps to send email in PHP.

Step 1- Open Xampp Directory.

Step 2- Go to C:\xampp\php and open the php.ini file.

Step 3- Press ctrl+f  and find mail function.

Step 4-  Change the following details like below code .


sendmail_from =

sendmail_path = "\"C:\xampp\sendmail\

sendmail.exe\" -t"

Step 5- Go to C:\xampp\sendmail .

Step 6- Open sendmail.ini

Step 7- Press ctrl+f  and find sendmail.

Step 8-  Change the following detail like below code






auth_password= hpxyz@123


Step 9- Create new file sendmail.php in C:\xampp\htdocs.

Step 10- Simply paste this code in sendmail.php and change the value according to you.


$to_email = "";  //Reciepient mail 

$subject = "Test mail";

$body = "hello, this is  test mail ";

$from_mail = "";  // your mail 


if (mail($to_email$subject$body$from_mail)) {

    echo "Email successfully sent to $to_email...";

else {

    echo "Email sending failed...";




Step 11- Go to then On the less secure app access setting. If this  is on then skip this step.

Step 12 - Now, Run send_mail.php file in your browser.