#!/usr/bin/php */ $sendmail_bin = '/usr/sbin/sendmail'; $logfile = '/tmp/mail_php.log'; //* Get the email content $logline = ''; $pointer = fopen('php://stdin', 'r'); while ($line = fgets($pointer)) { if(preg_match('/^to:/i', $line) || preg_match('/^from:/i', $line)) { $logline .= trim($line).' '; } $mail .= $line; } //* compose the sendmail command $command = 'echo ' . escapeshellarg($mail) . ' | '.$sendmail_bin.' -t -i'; for ($i = 1; $i < $_SERVER['argc']; $i++) { $command .= escapeshellarg($_SERVER['argv'][$i]).' '; } //* Write the log file_put_contents($logfile, date('Y-m-d H:i:s') . ' ' . $_ENV['PWD'] . ' ' . $_ENV['PATH_INFO'] . ' ' . $_ENV['SCRIPT_NAME'] . ' ' . $_ENV['SCRIPT_FILENAME'] . ' ' . $_ENV['REMOTE_ADDR'] . ' ' . $_ENV['HTTP_HOST'] . '' . ' ' . $logline . "\n", FILE_APPEND); //* Execute the command return shell_exec($command); ?>