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"
well,
${PWD}is short for “print working directory” (pwdis the command for that), and therefore it will give you only the working directory. that’s by design.also, the working directory doesn’t necessarily have anything todo with the full path of the script (neither your
sendmail2script, nor the php-script that callssendmail2).