Skip to content

Instantly share code, notes, and snippets.

@gjuric
Created July 1, 2016 11:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gjuric/6d59e72948716ec0bd258b98344356ad to your computer and use it in GitHub Desktop.
Save gjuric/6d59e72948716ec0bd258b98344356ad to your computer and use it in GitHub Desktop.
Script to open sent mail in Apple Mail
#!/usr/bin/env php
<?php
# Save this script somewhere and set you sendmail path in php.ini like this:
# sendmail_path = sudo -u <your_system_username> <path_to_script>/mail.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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment