Log instead of PHP mail()
(August 3, 2005)
Months ago I was looking for a solution to log outgoing mails
instead of sending them. This week I found a solution mentioned in Sean's PHP-Related Weblog.
For me only this part was interesting:
PHP:
<?php
$stdin = fopen('php://stdin', 'r');
$in = '';
while (!feof($stdin)) {
$in .= fread($stdin, 1024); // read 1kB at a time
}
?>
It allows you to read from stdin and grab the data that usually would be sent by mail.
To get this to work on Windows I needed to create a batch file that calls PHP with the PHP file as parameter:
c:apachephpphp.exe -q "c:wwwmaillogger.php"
And finally the path to the batch file needs to be set as sendmail_path in php.ini.
sendmail_path = "d:wwwmailloggermaillogger.bat"