Learn how to configure XAMPP to send mail from localhost using PHP with a clear, working setup for Gmail, exact paths, fixes, and common errors. Our 24/7 Live Support Team is always here to help you.


Sending emails from a local server is one of those tasks that sounds simple but often breaks at the worst time. A contact form looks perfect, the PHP code runs fine, yet no email ever arrives. If you’re using XAMPP, the issue isn’t PHP, it’s configuration.

In this guide, you’ll learn how to configure XAMPP to send mail from localhost using PHP with a setup that actually works. No theory dumps. Just the exact files, paths, and values you need.

configure XAMPP to send mail from localhost using PHP

Why Emails Fail on Localhost

By default, XAMPP doesn’t know how to route emails outside your machine. PHP’s mail() function depends on an SMTP service, and on localhost, that service doesn’t exist unless you configure one.

That’s why we use Sendmail, which comes bundled with XAMPP, and connect it to Gmail’s SMTP server.

Steps

Configure Sendmail in XAMPP

Go to:

C:\xampp\sendmail\sendmail.ini

Open the file in Notepad or any code editor and update the values below.

smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=tls
error_logfile=error.log
debug_logfile=debug.log
auth_username=yourgmail@gmail.com
auth_password=yourgmailpassword
force_sender=yourgmail@gmail.com
hostname=localhost

Save the file.

This step is critical because Sendmail is the engine that sends emails out from localhost.

Update PHP Mail Settings

Now open:

C:\xampp\php\php.ini

First, make sure OpenSSL is enabled. Find this line:

;extension=php_openssl.dll

Remove the semicolon so it becomes:

extension=php_openssl.dll

Next, scroll to the [mail function] section and update it exactly like this:

;SMTP=localhost
;smtp_port=25
;sendmail_from=
sendmail_path="C:\xampp\sendmail\sendmail.exe -t"

Save the file.

Restart XAMPP

This part gets skipped often, and then nothing works.

Open the XAMPP Control Panel and restart Apache. Without this, PHP won’t pick up your changes.

Test with PHP Mail Code

Create a file called testmail.php inside htdocs and paste this code:

<?php
$to = "receiver@example.com";
$subject = "Test Mail from Localhost";
$message = "Mail sent successfully using XAMPP and PHP.";
$headers = "From: yourgmail@gmail.com";
if(mail($to, $subject, $message, $headers)) {
echo "Mail sent successfully";
} else {
echo "Mail sending failed";
}
?>

Open it in your browser:

http://localhost/testmail.php

If configured correctly, the email will land in the inbox.

Fix Local PHP Mail Today

Chat animation


If Mail Still Doesn’t Send

Check the error logs here:

C:\xampp\sendmail\error.log
C:\xampp\sendmail\debug.log

These files tell you exactly what failed, authentication, port issues, or SSL problems.

Important Gmail Notes

  • Enable “Less secure app access” (or use an App Password if 2FA is on)
  • Make sure the Gmail ID matches auth_username and force_sender
  • Don’t keep duplicate sendmail_path entries in php.ini

Conclusion

Once set up, configure XAMPP to send mail from localhost using PHP becomes a one-time job. After that, contact forms, password resets, and email testing work smoothly on your local machine.

If you’re building or testing PHP projects regularly, knowing how to configure XAMPP to send mail from localhost using PHP saves hours of confusion. Set it once, test confidently, and move faster.