Created
February 16, 2014 11:26
-
-
Save StyleT/9032755 to your computer and use it in GitHub Desktop.
Sendmail handler (PHP edition)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Script save all letters from PHP mail function to mailFolder | |
* Usage: in php.ini - sendmail_path = php -f /path/to/sendmail.php | |
*/ | |
//Folder for saving files | |
define('DIR','/Users/StyleT/sendmail/'); | |
//получаем из потока тело письма | |
$stream = ''; | |
$fp = fopen('php://stdin','r'); | |
while($t=fread($fp,2048)) { | |
if ($t===chr(0)) { | |
break; | |
} | |
$stream .= $t; | |
} | |
fclose($fp); | |
//Сохраняем в файл | |
$fp = fopen(mkname(),'w'); | |
fwrite($fp,$stream); | |
fclose($fp); | |
//Функция присвоения имени файлу | |
function mkname($i=0){ | |
$fn = DIR.date('Y-m-d_H-i-s_').$i.'.eml'; | |
if (file_exists($fn)) { | |
return mkname(++$i); | |
} else { | |
return $fn; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment