When you try to use the mail() PHP function in your local computer, you get this message:
Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\test.php on line 14
Fortunately, I found a solution. In this tutorial I will show you how you can be able to use mail() function in your local computer with the help of Mozilla Thunderbird so you’ll know if your mail script really does work. In your XAMPP package, there’s a tool there called Mercury Mail. This app can, sort of, imitate an email provider like Gmail, Yahoo Mail, or others. But to set it up is a little bit tricky, took me hours to get it to work so I’d like to share this with you guys to save you time and frustration. 🙂
In case you’re wondering what Mercury Mail looks like or where to find it, here’s a snap shot:
Like for Apache and MySQL just hit Start to activate it and wait for Running to show. Then the Mercury Mail window pops up:
I started by creating a new user. Go to Configuration > Manage local users then Add. I put in the following:
Username: username Personal Name: personalname@localhost Mail Password:[same password you'll enter in thunderbird]
After entering all 3 info in User details window, click OK.
Then in Thunderbird, I created an account using the following credentials:
Your name: username Email Address: username@localhost password:[password set up in mercury mail] Server Type: POP3
Click Create Account.
Remember that error in the beginning? To get rid of it, I edited my php.ini file, search for sendmail_from and removed the semi-column (;) so that line isn’t a comment anymore (didn’t change the value).
;sendmail_from = postmaster@localhost
That’s it! But for this to work you have to restart your XAMPP. Once they’re back on (Apache, MySQL, and Mercury Mail) run your PHP script, this is how mine looks like:
<?php $recipient="username@localhost"; $subject="Test Email"; $mail_body="Nobody is going to get this email but me."; mail($recipient, $subject, $mail_body); ?>
And this is the result:
I hope you enjoyed this tutorial. I’ll be back for more 🙂