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_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.

$to = '';
$subject = 'Hello from XAMPP!';
$message = 'This is a test';
$headers = "From:\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. Required fields are marked *