How to configure XAMPP to send mail from localhost?

How to configure XAMPP to send mail from localhost?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

How to configure XAMPP to send mail from localhost

Sending email directly from a local development environment is a common requirement for testing application features, such as password reset flows or user registration notifications. However, configuring this on XAMPP often leads to confusion because the stack is designed primarily for serving web content, not acting as an SMTP relay server. To resolve this, you must understand that PHP's mail() function does not generate email by itself; it relies entirely on an external mail transfer agent (MTA) or a remote SMTP service.

When you attempt to send an email from a script running in XAMPP without explicit configuration, the system defaults to using the local Postfix, Sendmail, or Exim MTA if one is installed. Since XAMPP bundles its own Apache and PHP but does not typically include an MTA by default, your emails will fail silently or bounce unless you configure the underlying OS mail services correctly.

The most robust approach for a development environment is to bypass the local MTA entirely and connect directly to a remote SMTP server. This method ensures that your email delivery logic works consistently regardless of the local operating system's mail configuration state. You can achieve this by configuring PHP to act as an SMTP client rather than relying on the system mail() function.

To implement this, you need to modify your PHP environment variables or use a library like PHPMailer or Symfony Mailer. The core logic involves setting the SMTP host, port, authentication credentials, and encryption method. For example, if you are using Gmail for testing, you would configure the connection to use smtp.gmail.com on port 587 with TLS encryption. You must also ensure that your application uses an App Password rather than your standard login password, especially when two-factor authentication is enabled on the account.

Here is a conceptual example of how the configuration looks using PHPMailer within a Laravel or vanilla PHP context:

$mail = new PHPMailer\PHPMailer\PHPMailer(true);

try {
    // SMTP Configuration
    $mail->isSMTP();
    $mail->Host       = 'smtp.gmail.com';
    $mail->SMTPAuth   = true;
    $mail->Username   = 'your-email@gmail.com';
    $mail->Password   = 'your-app-password';
    $mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port       = 587;

    // Recipients
    $mail->setFrom('your-email@gmail.com', 'Your Application');
    $mail->addAddress('recipient@example.com');

    // Content
    $mail->isHTML(true);
    $mail->Subject = 'Test Email from XAMPP';
    $mail->Body    = 'This is a test email sent from localhost.';

    $mail->send();
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

Using this method removes the dependency on local mail server binaries like sendmail or postfix. It is important to note that relying on the default php.ini settings for sendmail_path will result in failures if no MTA is running locally. Therefore, explicitly defining SMTP credentials in your code is the recommended pattern for development.

If you are using Laravel, you can achieve this by creating a local environment file specific to your XAMPP setup or modifying the .env file within the config/mail.php settings. You would define the driver as smtp and populate the host, port, username, and password variables directly in the environment config. This keeps your credentials out of the main configuration file while allowing you to override them easily per environment.

One potential pitfall is firewall restrictions. Even if your local SMTP configuration is correct, some ISPs or corporate networks block outbound connections to common SMTP ports like 25 or 465 from localhost. In such cases, switching to port 587 with STARTTLS or 465 with SSL might be necessary depending on the provider's requirements. Additionally, always verify that your local firewall allows outgoing traffic on these ports, as XAMPP's Apache service running locally does not control network-level egress rules.

By shifting away from the system mail queue and utilizing a dedicated SMTP connection, you ensure that your email testing logic remains portable and reliable across different development machines. This approach aligns with modern best practices where the application handles the transport layer rather than relying on infrastructure assumptions about local mail agents.

Our network