I have a Xampp Server that I use only in a development environment. In order to preview emails that would be sent from the live sites without actually sending them I would like to intercept all the emails sent from this server. I would like to be able to either send them all to a specific email or save them as files instead of sending them to whatever address they're set to go to. This way I can make sure they are correct without accidently sending emails during testing.
Asked
Active
Viewed 664 times
4
1 Answers
4
You can accomplish this using the sendmail configuration within your php.ini.
Create a file named smtp_catcher.php
and the set the sendmail_path
sendmail_path = "php C:\path\to\file\smtp_catcher.php"
Then in your smtp_catcher.php
add this block:
#!/Applications/XAMPP/xamppfiles/bin
<?php
# create a filename for the emlx file
list($ms, $time) = explode(' ', microtime());
$filename = dirname(__FILE__).'/'.date('Y-m-d h.i.s,', $time).substr($ms,2,3).'.emlx';
# write the email contents to the file
$email_contents = fopen('php://stdin', 'r');
$fstat = fstat($email_contents);
file_put_contents($filename, $fstat['size']."\n");
file_put_contents($filename, $email_contents, FILE_APPEND);
# open up the emlx file (using Apple Mail)
exec('open '.escapeshellarg($filename));
?>
Now I am not sure what extension you'll need to use to view the emails but this should catch all emails going out.
NOTE: make sure that php is in your window's environment PATH

brenjt
- 15,997
- 13
- 77
- 118
-
Note that if php is not in our window's environment Path you may need to restart your computer after adding it before this will work. – MrMadsen Jul 07 '15 at 22:10