PHP mail() on Windows without a local mail server
This blog post is older than 4 years and may no longer be valid.
2 min read

PHP mail() on Windows


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: http://glob.com.au/sendmail/. 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\_from=your@email.de sendmail\_path = "\\"C:\\xampp\\sendmail\\sendmail.exe\\" -t"

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

$name = "Sender"; $recipient = "your@email.de"; $email = "recipients@email.de"; $mail\_body = "The text for the mail..."; $subject = "Subject for reviever"; $header = "From: ". $name . " <" . $email . ">\\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.