Skip to content

Instantly share code, notes, and snippets.

@michabbb
Created August 6, 2020 15:09
Show Gist options
  • Save michabbb/9155affd1dad4bc94f59345eb0e4cc9d to your computer and use it in GitHub Desktop.
Save michabbb/9155affd1dad4bc94f59345eb0e4cc9d to your computer and use it in GitHub Desktop.
debugging sendmail php
/usr/local/bin/phpsendmail
==================================================================================================
#!/usr/local/bin/php
<?php
/**
This script is a sendmail wrapper for php to log calls of the php mail() function.
Author: Till Brehm, www.ispconfig.org
(Hopefully) secured by David Goodwin <david @ _palepurple_.co.uk>
*/
$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'] . ' ' . $logline.' '.getenv('__PATH_INFO').' '.getenv('__SCRIPT_NAME').' '.getenv('__SCRIPT_FILENAME')."\n", FILE_APPEND);
//* Execute the command
return shell_exec($command);
==================================================================================================
nginx host config
==================================================================================================
fastcgi_param PHP_VALUE "auto_prepend_file=/home/xxxxxxx/htdocs/set_php_headers.php";
==================================================================================================
set_php_headers.php
<?php
putenv("__PATH_INFO=". $_SERVER["PATH_INFO"]);
putenv("__SCRIPT_NAME=". $_SERVER["SCRIPT_NAME"]);
putenv("__SCRIPT_FILENAME=". $_SERVER["SCRIPT_FILENAME"]);
putenv("__REMOTE_ADDR=". $_SERVER["REMOTE_ADDR"]);
putenv("__HTTP_HOST=". $_SERVER["HTTP_HOST"]);
==================================================================================================
php.ini
==================================================================================================
[mail function]
sendmail_path = /usr/local/bin/phpsendmail
==================================================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment