Test send PHP emails locally (xampp) Windows

If you are required to test the functionality of PHP mail in your projects, which is without having to use external mail server, you can try these steps which will allow you to send and open emails locally.I assume you are running XAMPP server on your computer, it should work fine with WampServer too without any configuration.

Step 1 : Download email server

Test mail server is tiny mail server program for windows, which you can install on your computer and start running instantly. You can download the program here.

Step 2 : Make changes in PHP.ini

Open your PHP.ini file, scroll down to [mail function] and make changes as shown in picture below. php-ini-settings

Step 3. Mail Header

When you write PHP mail script, include mail header with "From: [email protected]", otherwise, you might end up with bizarre error like so:
  • 1
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in ___ on line 123
Here's what my testing PHP email look like :
PHP
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
<?php $body = "This is the \nbody of my email."; $headers = 'From: [email protected]' . "\r\n" .'Reply-To: [email protected]'; // send email mail("[email protected]", "My subject", $body, $headers); ?>

Step 4 : Start Mail Server

Now restart your server, and create a PHP email as I've instructed above then send it, then the program will capture any email sent using XAMPP server, which you can open and read normally using any email program such as "Outlook express" or "Thunderbird".
  • Thanks for all of your helpful posts. They are much appreciated. I had one small problem with this one. I changed the php.ini file as directed and then tested my email script. When it didn't work, I checked all the usual things, but nothing appeared incorrect. I went back to my php.ini file and turned on mail logging by un-commenting this line: mail.log = "C:\xampp\php\logs\php_mail.log" Then the brain fog cleared and I realized that I had not restarted the web server after the initial config change. After restarting Apache in XAMPP, it worked great. So a reminder to restart the web server would be helpful.
New question is currently disabled!