该问题与此处的问题相关:
尝试做同样的事情,但无法让日志输出我需要的内容。我对 serverfault 不太熟悉,理想情况下,我会发布我对原始问题的后续评论,或者 PM adam 看看他是否找到了解决方案,但看起来 serverfault 不是这样工作的。我可以发布一个“答案”,但这绝对不是答案。
我有一个位于 /usr/local/bin/sendmail-php-logged 的脚本,内容如下:
#!/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 $*
这是记录到 /var/log/maillog,但正如 Adam 在他的问题中提到的,所有服务器变量都不起作用。我得到的输出是:
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
用户 ID、当前用户和密码均有效,可能是因为它们是全局可访问的脚本资源,而不是特定于 PHP 的,就像所有其他资源一样。我尝试按照 labradort 的说明使用其他服务器变量,但毫无效果。
以下是一些示例测试:
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
输出结果如下:
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:
我正在运行 php 5.3.10。不幸的是,为了与旧系统兼容,register_globals 已打开,但您不会认为这会导致环境变量停止工作。
如果有人能给我一些提示,告诉我为什么这可能不起作用,我会非常高兴:)
答案1
也许我遗漏了什么,但我在 PHP 文档中没有看到任何关于将创建环境的内容。为什么不将记录器语句设置为类似于以下内容的内容,logger -p mail.info thelog $*
这将为您提供传递给 sendmail 的选项?或者也许只是启用邮件日志
答案2
如果你有 PHP 5.3 及以上版本,请打开php.ini
并找到以下行
mail.log =
写入要记录的文件的完整路径,并授予其 chmod 664 访问权限。这样,您就可以读取和写入它,但不能执行,因为它只是一个日志文件