How to Send Mail from Localhost XAMPP using sendmail and Gmail SMTP

Advertisement

Google AdSense In-Article Display Placement

Publisher ID: ca-pub-XXXXXXXXXXXXXXXX (Configured in config.php)

By default, PHP mail() does not work on localhost because Windows lacks a native sendmail daemon. XAMPP includes a sendmail utility that connects to SMTP.

✔ Rapid Direct Solution

Edit "C:\xampp\sendmail\sendmail.ini", set smtp_server=smtp.gmail.com, smtp_port=587, and provide your email and Google App Password (not your main password). Next, edit "C:\xampp\php\php.ini" and set sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t". Restart Apache.

1. Problem Diagnosis & Symptoms

Local contact forms and password reset emails fail silently without an SMTP relay.

2. Primary Root Causes

  • Cause: Missing SMTP credentials in sendmail.ini.

3. Step-by-Step Diagnostic Fixes

1

Configure sendmail.ini

Edit C:\xampp\sendmail\sendmail.ini:

INI
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=tls
auth_username=youremail@gmail.com
auth_password=your_16_char_app_password

4. How to Verify the Resolution

  • ✔ Create test_mail.php: mail("target@example.com", "Test", "Body"); and verify delivery.

5. Diagnostic Troubleshooting Matrix

Symptom Observed Root Cause Recommended Action
sendmail error: 535-5.7.8 Username and Password not accepted Using standard Gmail password instead of App Password Generate a dedicated 16-character App Password in Google Account Security

6. Critical Mistakes to Avoid

  • ❌ Never share your app password in public Git commits.

7. Frequently Asked Questions

❓ Is it better to use PHPMailer instead of PHP mail()?

Yes! PHPMailer or Symfony Mailer provides direct SMTP connection without needing sendmail.ini.

Official Technical References

Advertisement

Google AdSense In-Article Matched Content Unit