Install runkit module:
wget https://github.com/downloads/zenovich/runkit/runkit-1.0.3.tgz tar xf runkit*.tgz cd runkit-1.?.? phpize ./configure make make install
Edit php.ini:
extension=runkit.so runkit.internal_override=1 auto_prepend=/sendmail_tracker.php
Create /sendmail_tracker.php:
touch /sendmail_tracker.php chown root:root /sendmail_tracker.php chmod 755 /sendmail_tracker.php
Edit /sendmail_tracker.php:
<?php runkit_function_redefine('mail','',' $mail_args = func_get_args(); $sendmail_tracker_log = "\n\n".date("d.m.y H:i:s") . "\n"; $sendmail_tracker_log .= "### Start Mail\n"; $sendmail_tracker_log .= "Script: ".$_SERVER[\'SCRIPT_FILENAME\']."\n\n"; $sendmail_tracker_log .= "Mail to: ".$mail_args[0]."\n"; $sendmail_tracker_log .= "Mail subject: ".$mail_args[1]."\n"; $sendmail_tracker_log .= "Args: ".print_r(func_get_args(),TRUE)."\n"; $sendmail_tracker_log .= "\n### End Mail"; $sendmail_tracker_fp = fopen("/var/log/sendmail_tracker_log","a+"); fwrite( $sendmail_tracker_fp, $sendmail_tracker_log); fclose( $sendmail_tracker_fp ); unset($sendmail_tracker_log); unset($sendmail_tracker_fp); unset($mail_args); '); ?>
Create logfile:
touch /var/log/sendmail_tracker_log && chmod 666 /var/log/sendmail_tracker_log
Restart Apache
Read logfile:
tail -f /var/log/sendmail_tracker_log | grep Script