Skip to content

How to Configure XAMPP to Send Email from Localhost with PHP

It is often necessary to configure the XAMPP server for sending email from the localhost using PHP. To meet that goal, you need to make changes to two files: sendmail.ini and php.ini. Here, we will outline the steps you need to take to achieve this.

Steps to Send an Email with the help of XAMPP

Below, you can find the steps to configure XAMPP for sending emails from the local host with PHP.

Step 1: XAMPP Installation Directory

The first step is opening the XAMPP Installation Directory.

Step 2: Open php.ini

The second step is going to C:/xampp/php and opening the php.ini file.

Step 3: Find [mail function]

In this step, press Ctrl + F to find [mail function].

Step 4: Configure php.ini Settings

Now, it is necessary to locate and update the values as shown below:

php.ini configuration

ini
sendmail_from = [email protected]
sendmail_path = "C:/xampp/sendmail/sendmail.exe -t"

Note: sendmail_from is often ignored by modern sendmail wrappers. Use force_sender in sendmail.ini instead for reliable results.

Step 5: Open sendmail.ini

The next step is going to C:/xampp/sendmail and opening the sendmail.ini file.

Note: sendmail.exe is a third-party wrapper included with XAMPP. Verify that your XAMPP version includes this file, as its presence may vary across releases.

Step 6: Find [sendmail]

Press Ctrl + F to find [sendmail].

Step 7: Configure sendmail.ini Settings

The next step is to locate and update the values as shown below:

sendmail.ini configuration

ini
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username[email protected]
auth_password=your_app_password
force_sender[email protected]

Note: Google explicitly blocks standard SMTP authentication. You must generate an App Password in your Google Account security settings and use it for auth_password.

Step 8: Restart Apache

After saving both configuration files, restart the Apache server in the XAMPP Control Panel. This ensures that the new settings are loaded and take effect.

Script for Sending Email

Finally, let’s see how the script for sending emails looks like:

PHP email script

php
<?php

$to_email = "[email protected]";
$subject = "Simple Email Testing via PHP";
$body = "Hello,\nIt is a testing email sent by PHP Script";
$headers = "From: [email protected]\r\n";

if (mail($to_email, $subject, $body, $headers)) {
  echo "Email successfully sent to $to_email...";
} else {
  echo "Email sending failed...";
}

?>

Note: The mail() function is deprecated in PHP 8.1 and removed in PHP 8.2. This guide only works on PHP 8.1 or lower. For modern applications, use a dedicated library like PHPMailer or Symfony Mailer.

Save this file as send_test.php in your C:/xampp/htdocs directory. Start the Apache server in the XAMPP Control Panel, then open http://localhost/send_test.php in your browser to run the test.

After following the steps above, you will manage to send an email. However, if you still face problems in sending an email, then the reason can be among the following:

  1. An incorrect port number.
  2. A wrong password.
  3. Emails are delayed.
  4. Gmail security settings block the connection.
  5. Wrong email configuration.

What is XAMPP?

XAMPP is a free and open-source cross-platform web server solution stack package. It is designed and developed by Apache Friends. It consists of the MariaDB database, Apache HTTP Server, as well as interpreters for scripts written in the PHP and Perl programming languages.

Dual-run preview — compare with live Symfony routes.