Skip to content

Instantly share code, notes, and snippets.

@Tobur
Created July 19, 2013 08:34
Show Gist options
  • Save Tobur/6037641 to your computer and use it in GitHub Desktop.
Save Tobur/6037641 to your computer and use it in GitHub Desktop.
<?php
//insert into php.ini
//sendmail_path = "/usr/local/bin/php /localetc/sendmail_stub/fake.php"
$sendMailStubObj = new SendMailStub();
$sendMailStubObj->main();
class SendMailStub
{
private $_saveEmailsPath = "/home/tobur/mail/";
function main()
{
//--- get email from the stream ---//
$stream_data = '';
$stream_handler = fopen('php://stdin', 'r');
while ($t = fread($stream_handler, 2048)) {
if ($t === chr(0))
break;
$stream_data .= $t;
}
fclose($stream_handler);
//save to file
$fwrite_handler = fopen($this->_generateUniquePath(), 'w');
fwrite($fwrite_handler, $stream_data);
fclose($fwrite_handler);
}
private function _generateUniquePath()
{
$i = 0;
do {
$path = $this->_saveEmailsPath . $this->_generateFname($i);
$i++;
if($i > 100){
break;
}
} while (file_exists($path) == true);
return $path;
}
private function _generateFname($i = 0)
{
$parts = array(
date('Y-m-d_H-i-s'),
);
if ($i > 0) {
$parts[] = "_{$i}";
}
$parts[] = ".eml";
$fname = implode("", $parts);
return $fname;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment