PHP mail() on Windows

Reading Time: < 1 minute

Setting up an email server on Windows can be a real pain. Hardly worth the effort when all I want to do is using PHP’s mail() function.

I found a nice workaround when I updated my XAMPP installation: All you need is an SMTP server somewhere that you can use, because sendmail.exe will just forward the emails to it.

You still need to configure it though:

  1. Configure your SMTP in the sendmail.ini (located usually under C:\xampp\sendmail)
  2. In the php.ini, ensure you have the following set up
    [mail function]
    sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"[/code]

That’s it. Now you can quickly test it (below script more or less stolen from

[code lang=”php”]
$name = "Sender";
$recipient = "";
$email = "";
$mail_body = "The text for the mail…";
$subject = "Subject for reviever";
$header = "From: ". $name . " &lt;" . $email . "&gt;\r\n";

mail($recipient, $subject, $mail_body, $header);

If everything is set up correctly, you should notice that the execution of the script takes a moment. If it runs through fast, something did not work – or you have a really fast machine & connection.

Note: although I had some config errors the first time the error.log in the sendmail directory was not populated with any messages. I don’t know when this file will actually be used.

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept the Privacy Policy

This site uses Akismet to reduce spam. Learn how your comment data is processed.