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:
- Configure your SMTP in the sendmail.ini (located usually under C:\xampp\sendmail)
- In the php.ini, ensure you have the following set up
[mail function] firstname.lastname@example.org 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 = "email@example.com"; $email = "firstname.lastname@example.org"; $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.