Localhost refers to the local computer or server that is used for testing and development purposes. It allows developers to create and test websites or web applications on their own machines before deploying them to a live server. XAMPP, which stands for Cross-Platform, Apache, MySQL, PHP, and Perl, is a popular software package that provides a complete web development environment. It includes all the necessary components, such as a web server, a database server, and a scripting language, to set up a local server environment quickly and easily. In this blog we will learn how to send mail from localhost XAMPP using gmail.

Why need to send mail from localhost?

When developing a website or an application, it is often necessary to incorporate email functionality, such as sending registration confirmations, password reset links, or notifications to users. However, testing email functionality on a local development environment can be challenging since local servers usually do not have built-in email services. This is where the need to send mail from localhost arises. By configuring a local server like XAMPP to send emails, developers can simulate the email sending process and ensure that their code works correctly before deploying it to a live server.

Why use Gmail for sending emails?

One of the most popular and reliable ways to send emails from a local server is by utilizing Gmail’s SMTP (Simple Mail Transfer Protocol) server. Gmail offers a secure and straightforward method to send emails programmatically using SMTP. By leveraging Gmail’s SMTP server, developers can take advantage of Gmail’s robust email infrastructure, ensuring that their emails are delivered successfully to the recipients’ inboxes. In this blog, we will explore the process of setting up XAMPP to send emails using Gmail and demonstrate how to write a PHP script that utilizes Gmail’s SMTP server to send emails from a localhost environment.

Steps to Send Mail From Localhost XAMPP Using Gmail:

Step 1: Open XAMPP Installation Directory

Step 2: Go to C:\xampp\php 

Step 3: open php.ini file

Step 4: Find [mail function] by using search (You can search using ctrl + f)

Step 5: Search and pass the following values:

sendmail_from = YourGmailId@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

Step 6: Go to C:\xampp\sendmail and open sendmail.ini file.

Step 7: Find [sendmail] using ctrl + f

Step 8: Search and pass the following values


Script To Send Mail:

$to_email = "receipient@gmail.com";
$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...";

That’s all!

How to turn on ‘Less Secure Apps’ settings as a mailbox user:

  • Open Google Account
  • Click on ‘Security’ from the left navigation panel
  • Turn ON from the Less secure app access panel on the bottom of the page & Save

If you are still facing issues with sending mail from localhost using Gmail, the problem could be attributed to one of the following reasons:

  • The mails are being sent late
  • The mail is not configured properly
  • Port might be blocked
  • Gmail does not have sufficient permissions
  • Password might be wrong


Being able to send mail from localhost using XAMPP and Gmail is an essential skill for web developers and testers. By following the steps outlined in this blog, you can easily configure your XAMPP environment to send emails using Gmail’s SMTP server. However, if you find the process challenging or time-consuming, you may consider hiring a Magento developer service to assist you.