Skip to content

Instantly share code, notes, and snippets.

@schmkr
Last active December 11, 2015 17:28
Show Gist options
  • Save schmkr/4634605 to your computer and use it in GitHub Desktop.
Save schmkr/4634605 to your computer and use it in GitHub Desktop.
Script to catch mails on development machines
#!/usr/bin/env php
<?php
# create a filename for this email
list($ms, $time) = explode(' ', microtime());
$filename = '/tmp/'.date('Y-m-d h.i.s,', $time).substr($ms,2,3).'.txt';
# 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 txt file (using Apple Mail)
exec('open -a "/Applications/Google Chrome.app" '.escapeshellarg($filename));
@schmkr
Copy link
Author

schmkr commented Jan 25, 2013

Original is from this blog: http://blogs.bigfish.tv/adam/2009/12/03/setup-a-testing-mail-server-using-php-on-mac-os-x/.

Though this does not open the Mail app, it saves the email as an txt file and opens up Chrome.

@schmkr
Copy link
Author

schmkr commented Jan 25, 2013

And only need to change this in php.ini

sendmail_path = "/usr/local/bin/smtp_catcher"

Or wherever the script is stored.

And don't forget to put the executable flag on the file

@maximuff13
Copy link

is there a trick to get it run with OS X 10.10 and XAMPP 1.8.3-5 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment