To send mail from localhost XAMPP using Gmail
configure XAMPP after installing it.
Follow the below steps for the same.
Steps to Send Mail From Localhost XAMPP Using Gmail 👇🏻
smtp_port=587 or 25 //use any of them
Here is the actual code that you have to write
Script To Send Mail:
$to_email = "email@example.com";
$subject = "Simple Email Test via PHP";
$body = "Hi, This is test email send by PHP Script";
$headers = "From: sender email";
if (mail($to_email, $subject, $body, $headers))
echo "Email successfully sent to $to_email...";
echo "Email sending failed...";
Note: If you are getting a warning message then Please configure “Less secure apps” settings as shown below. Sometimes without turning on the ‘less secure apps’ is the main reason the user didn’t receive the mail.
Turning on ‘less secure apps’ settings as mailbox user.
Go to your (Google Account).
On the left navigation panel, Click Security.
On the bottom of the page, in the Less secure app access panel, click Turn on access.
If you don’t see this setting, your administrator might have turned off less secure app account access (check the instruction above).
Click the Save button.
Now your email will be sent successfully. Have a good day and please share your story in the comment box.