XAMPP is Cross-Platform (X), Apache (A), MariaDB (M), PHP (P) and Perl (P). It is for developers to create a local webserver for testing or deployment purposes.
As a part of testing, developers need to send emails that are always going to be there when it comes to online businesses.
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:
1. Open XAMPP Installation Directory.
2. Go to C:\xampp\php and open the php.ini file.
3. Find [mail function] by pressing ctrl + f.
4. Search and pass the following values:
SMTP=smtp.gmail.com smtp_port=587 sendmail_from = [email protected] sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
5. Now, go to C:\xampp\sendmail and open sendmail.ini file.
6. Find [sendmail] by pressing ctrl + f.
7. Search and pass the following 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 $to_email = "[email protected]"; $subject = "Simple Email Test via PHP"; $body = "Hi,nn This is test email send by PHP Script"; $headers = "From: sender\'s email"; if (mail($to_email, $subject, $body, $headers)) { echo "Email successfully sent to $to_email..."; } else { echo "Email sending failed..."; }
Hope this guide will be helpful!
Note:
Please configure “Less secure apps” settings as shown at https://support.google.com/cloudidentity/answer/6260879 for proper working.
Also, if you are still facing issues, the reason can be one of the below:
1. The mails are being sent late
2. The mail is not configured properly
3. The port is blocked
4. Gmail does not have required permissions
5. Password is wrong
Feel free to share the solution via social media.
Thanks!