Skip to content

Instantly share code, notes, and snippets.

@ariunbayar
Created September 23, 2014 06:39
Show Gist options
  • Save ariunbayar/f56a1c96348eb2d282bc to your computer and use it in GitHub Desktop.
Save ariunbayar/f56a1c96348eb2d282bc to your computer and use it in GitHub Desktop.
Logs your sent email for PHP.
#!/usr/bin/php
<?php
/*
* Don't forget to set following in your php.ini:
* sendmail_path = /path/to/mail_log.php
*
* You can test with following php code:
* mail('user@email.dev', 'subject', 'body');
*/
$mail = '';
$pointer = fopen('php://stdin', 'r');
while ($line = fgets($pointer)) {
$mail .= $line;
}
$title = 'Email at '.date('Y-m-d H:i:s');
$content = "----------------------------\n"
.$title."\n"
."----------------------------\n"
.$mail."\n\n";
$cmd = '/usr/bin/notify-send';
$cmd .= ' ' . escapeshellarg($title);
$cmd .= ' ' . escapeshellarg($mail);
shell_exec($cmd);
file_put_contents('/run/shm/mail.log', $content, FILE_APPEND);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment