clock  Mon - Sun 8.00 AM - 8.00 PM
fb
instagram
play store
pinterest

How to send mail using PHP

writter  Hariom Prajapati
Date  26 Jun 2022
Language  PHP
How to send mail using PHP

How to send mail using PHP

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 .

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = [email protected]
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

smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username= [email protected]
auth_password= [email protected]
force_sender= [email protected]

 

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.

<?php
$to_email = "[email protected]";  //Reciepient mail 
$subject = "Test mail";
$body = "hello, this is  test mail ";
$from_mail = "[email protected]";  // 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 myaccount.google.com/ security 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.

 

Result–