How to send mail from localhost XAMPP using PHP?

Today, We want to share with you send mail from localhost.In this post we will show you how to use mail function in php?, hear for php code for sending email we will give you demo and example for implement.In this post, we will learn about Send Email Via Gmail SMTP Server In Laravel 7/6 with an example.

How to Send Mail from Localhost XAMPP Using Gmail

Steps to Send Mail From Localhost XAMPP Using Gmail:

  • first of all Open XAMPP Installation Folder.
  • and then Go to C:\xampp\php and open the php.ini file.
  • Search [mail function] by pressing ctrl + f.

Search and pass the bellow values:

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = [email protected]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

  • Now, go to C:\xampp\sendmail and open sendmail.ini file.
  • Search [sendmail] by pressing ctrl + f.

Search and pass the bellow values

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=Your-Gmail-Password
[email protected](optional)

Script To Send Mail:

<?php
$send_to_address = "[email protected]";
$mail_subject = "send mail using smtp in php";
$body = "How to Send an Email via Gmail SMTP Server using PHP";
$headers = "From: sender\'s email";

if (mail($send_to_address, $mail_subject, $body, $headers)) {
    echo "Good Luck Email successfully sent to $send_to_address...";
} else {
    echo "Sorry, Your Email sending failed...";
}

How to Send Mail from Localhost XAMPP Using Gmail?

To php send mail from localhost XAMPP using Gmail via google account, some basic configure XAMPP after installing it.
There are the some Follow the below step by step for the same.

Read Also:  Laravel 6 Install Constant Contact - PHP Examples

Steps to Send Mail From Localhost XAMPP Using Gmail:

Open XAMPP Installation Directory.

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

Find [mail function] by pressing ctrl + f.
there Search as well as pass key and value the bellow values:

SMTP=smtp.gmail.com
smtp_port=587 or 25
sendmail_from = [email protected]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

Now, go to C:\xampp\sendmail and open the sendmail.ini file.

Find [sendmail] by pressing ctrl + f.
here simple Search and pass the bellow key and values

smtp_server=smtp.gmail.com
smtp_port=587 or 25 //use any of them
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=Your-Gmail-Password
[email protected](optional)

Script To Send Mail:

<?php
$send_to_address = "[email protected]";
$mail_subject = "Ajax Autocomplete Search Using JQuery With PHP MySQLi";
$body = "Bootstrap Autocomplete Search Box / Textbox In PHP MySQL";
$headers = "From: sender email";

if (mail($send_to_address, $mail_subject, $body, $headers)) {
    echo "Good Luck Email successfully sent to $send_to_address...";
} else {
    echo "Sorry, Your Email sending failed...";
}

**Note: If you are getting a some warning message then Please configure “Less secure apps” web settings as shown below. Sometimes without turning on the ‘less secure apps’ is the main reason the user didn’t get the mail.

Read Also:  PHP Toggle Like Dislike Rating System using jQuery Ajax

=> Turning on ‘less secure apps’ settings as mailbox user

  • Go to your (Google Gmail Account).
  • On the left navigation Admin panel, click Security options.
  • On the bottom of the web page, in the Less secure app access panel, and then click Turn on access.
  • If you don’t display this setting, your some administrator might have turned off less secure application account
  • access (check the instruction above).

  • Click the Save button.

** And Last step your email Address will be sent successfully.

I hope you get an idea about send mail from localhost.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.