Skip to content

Instantly share code, notes, and snippets.

@forsvunnet
Created September 29, 2016 14:35
Show Gist options
  • Save forsvunnet/eba15688179f6d2a399c2eba33a9bb88 to your computer and use it in GitHub Desktop.
Save forsvunnet/eba15688179f6d2a399c2eba33a9bb88 to your computer and use it in GitHub Desktop.
phpsendmail
#!/usr/bin/php
<?php
date_default_timezone_set('CET');
/**
* This script is a sendmail wrapper for php to log calls of the php mail() function.
*/
//* Get the email content
$logline = '';
$pointer = fopen('php://stdin', 'r');
$mail = '';
while ($line = fgets($pointer)) {
if(preg_match('/^to:/i', $line) || preg_match('/^from:/i', $line)) {
$logline .= trim($line).' ';
}
$mail .= $line;
}
$mail = quoted_printable_decode( $mail );
$id = date( 'Y-m-d_H:i:s') .'_'. uniqid();
//* Write the log
file_put_contents('/vagrant/mail/'. $id .'.html', $mail);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment