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.

Leave a Reply

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