Output php mail calls to log file
Posted
by
Tom McQuarrie
on Server Fault
See other posts from Server Fault
or by Tom McQuarrie
Published on 2012-10-04T03:15:26Z
Indexed on
2012/10/04
3:40 UTC
Read the original article
Hit count: 561
This question relates to the question found here:
Find the php script thats sending mails
Trying to do the exact same thing but can't get the log to output what I need. Not too experienced with serverfault and ideally I'd post my followup on the original question, or PM adam to see if he ever found a solution, but looks as though server fault doesn't work that way. I can post an "answer" but that's definitely not what this is.
I have a script located at /usr/local/bin/sendmail-php-logged, with the following:
#!/bin/sh
logger -p mail.info sendmail-php: site=${HTTP_HOST}, client=${REMOTE_ADDR}, script=${SCRIPT_NAME}, filename=${SCRIPT_FILENAME}, docroot=${DOCUMENT_ROOT}, pwd=${PWD}, uid=${UID}, user=$(whoami)
/usr/sbin/sendmail -t -i $*
This is logging to /var/log/maillog, but as Adam mentions in his question, none of the server variables work. Output I'm getting is:
Oct 4 12:16:21 fluke logger: sendmail-php: site=, client=, script=, filename=, docroot=, pwd=/var/www/html/aro_chroot/sites/arocms, uid=48, user=apache
Oct 4 12:16:21 fluke logger: sendmail-php: site=, client=, script=, filename=, docroot=, pwd=/var/www/html/aro_chroot/sites/arocms, uid=48, user=apache
Oct 4 12:17:03 fluke logger: sendmail-php: site=, client=, script=, filename=, docroot=, pwd=/var/www/html/aro_chroot/sites/arocms, uid=48, user=apache
Oct 4 12:17:05 fluke logger: sendmail-php: site=, client=, script=, filename=, docroot=, pwd=/root, uid=0, user=root
Oct 4 12:17:11 fluke logger: sendmail-php: site=, client=, script=, filename=, docroot=, pwd=/var/www/html/aro_chroot/sites/arocms, uid=48, user=apache
Oct 4 12:17:14 fluke logger: sendmail-php: site=, client=, script=, filename=, docroot=, pwd=/root, uid=0, user=root
Oct 4 12:17:29 fluke logger: sendmail-php: site=, client=, script=, filename=, docroot=, pwd=/root, uid=0, user=root
Oct 4 12:17:41 fluke logger: sendmail-php: site=, client=, script=, filename=, docroot=, pwd=/root, uid=0, user=root
User ID, current user, and pwd are all working, probably because they're globally accessible script resources, and not specific to PHP, like all the others are. I've tried using other server variables as per labradort's instructions, but no joy.
Here's some sample tests:
logger -p mail.info sendmail-php SCRIPT_NAME: ${SCRIPT_NAME}
logger -p mail.info sendmail-php SCRIPT_FILENAME: ${SCRIPT_FILENAME}
logger -p mail.info sendmail-php PATH_INFO: ${PATH_INFO}
logger -p mail.info sendmail-php PHP_SELF: ${PHP_SELF}
logger -p mail.info sendmail-php DOCUMENT_ROOT: ${DOCUMENT_ROOT}
logger -p mail.info sendmail-php REMOTE_ADDR: ${REMOTE_ADDR}
logger -p mail.info sendmail-php SCRIPT_NAME: $SCRIPT_NAME
logger -p mail.info sendmail-php SCRIPT_FILENAME: $SCRIPT_FILENAME
logger -p mail.info sendmail-php PATH_INFO: $PATH_INFO
logger -p mail.info sendmail-php PHP_SELF: $PHP_SELF
logger -p mail.info sendmail-php DOCUMENT_ROOT: $DOCUMENT_ROOT
logger -p mail.info sendmail-php REMOTE_ADDR: $REMOTE_ADDR
And the output:
Oct 4 12:58:02 fluke logger: sendmail-php SCRIPT_NAME:
Oct 4 12:58:02 fluke logger: sendmail-php SCRIPT_FILENAME:
Oct 4 12:58:02 fluke logger: sendmail-php PATH_INFO:
Oct 4 12:58:02 fluke logger: sendmail-php PHP_SELF:
Oct 4 12:58:02 fluke logger: sendmail-php DOCUMENT_ROOT:
Oct 4 12:58:02 fluke logger: sendmail-php REMOTE_ADDR:
Oct 4 12:58:02 fluke logger: sendmail-php SCRIPT_NAME:
Oct 4 12:58:02 fluke logger: sendmail-php SCRIPT_FILENAME:
Oct 4 12:58:02 fluke logger: sendmail-php PATH_INFO:
Oct 4 12:58:02 fluke logger: sendmail-php PHP_SELF:
Oct 4 12:58:02 fluke logger: sendmail-php DOCUMENT_ROOT:
Oct 4 12:58:02 fluke logger: sendmail-php REMOTE_ADDR:
I'm running php 5.3.10. Unfortunately register_globals is on, for compatibility with legacy systems, but you wouldn't think that would cause the environment variables to stop working.
If someone can give me some hints as to why this might not be working I'll be a very happy man :)
© Server Fault or respective owner