Sending email from localhost when using XAMPP and WordPress on Windows

It is often handy in a local test environment to be able to send emails to test various functionality. There is lots of information regarding this for a Unix setup, but for Windows it was a little less clear at first.

In my previous version of XAMPP this proved quite easy. It turned out all I had to do was find the php.ini file ie C:\xampp\php\php.ini and uncomment the lines in the [mail function] section for Win32 only ie

  • SMTP=localhost
  • smtp_port=25

For some reason once I upgraded to the latest version of XAMPP it didn’t work quite as easily. I had to use one of my real email SMTP host names and ports. In the end I found that

  • SMTP=smtp.telstra.com
  • smtp_port=587

worked nicely.

You can find a little more information regarding these settings in the PHP documentation for the PHP mail function.

I also found this little mail test script handy.

<?php
$to = 'recipients@email-address.com';
$subject = 'Hello from XAMPP!';
$message = 'This is a test';
$headers = "From: your@email-address.com\r\n";
if (mail($to, $subject, $message, $headers)) {
   echo "SUCCESS";
} else {
   echo "ERROR";
}

This script and more information about it can be found in the XAMPP documentation Send Mail with PHP.

Leave a Reply

Your email address will not be published.