I am totally unfamiliar with bash scripting, however I came across the following script that php's sendmail routes through so I can trace any scripts that may be comprised by spammers.
This works great however the $PWD variable is not showing the file name, its only showing the file's working directory.
Bash script: /usr/local/bin/sendmail2
#!/bin/sh
# Logging sendmail wrapper
SENDMAIL="/usr/sbin/sendmail -t -i"
LOGFILE="/home/mail.log"
DT=`date "+%Y-%m-%d %H:%M:%S"`
DTFN=`date "+%Y%m%d-%H%M%S"`
#TMPFP=`tempfile --prefix=lsm_`
TMPFP=`mktemp`
cat | tee "$TMPFP" | $SENDMAIL $*
RETVAL=$?
TO=`grep "To:" <"$TMPFP"`
rm -f "$TMPFP"
echo "$DT: $PWD sent $TO" >> $LOGFILE
exit $RETVAL
Test script: /home/mysite/test.php:
<?php
$to = "my@email.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "my@email.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
php.ini:
sendmail_path = "/usr/local/bin/sendmail2"