Skip to content

Instantly share code, notes, and snippets.

@ivanhoe011
Forked from gjuric/mail.php
Created July 1, 2016 13:19
Show Gist options
  • Save ivanhoe011/3e08f75fa7a9d8c385b788376733880b to your computer and use it in GitHub Desktop.
Save ivanhoe011/3e08f75fa7a9d8c385b788376733880b 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