Do You PHP はてブロ

Do You PHPはてなからはてブロに移動しました

mail.log、mail.add_x_headerディレクティブが追加されたので試してみた

なにやらcvsにcommitされた模様。


The mail.log directive allows you to specify the file where each call to mail() will be logged. The log file will contain the path and line # of the calling script in addition to all of the headers indicated by the user.

The mail.add_x_header directive will introduce a X-PHP-Originating-Script header that will contain the file name (no path) of the calling script and the uid of the script. This combination should be sufficient for the admin to locate the sending script.

php.ini-recommendedにも

; Add X-PHP-Originaiting-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off

; Log all mail() calls including the full path of the script, line #, to address and headers
mail.log =

のような内容が追加されており、両者ともデフォルトでは無効です。
とりあえず、PHP5.3.0α4-dev(php5.3-200901111130)で確認してみました。php.iniの設定は

mail.add_x_header = On
mail.log = /path/to/mail.log

として、PHPスクリプト

<?php
mail('shimooka', 'test', 'hogehoge');

といった内容です。
これをCLIPHPから実行し、mailコマンドでメールヘッダを確認すると、

From shimooka@localhost.localdomain  Sun Jan 11 23:51:09 2009
Date: Sun, 11 Jan 2009 23:51:01 +0900
From: shimooka@localhost.localdomain
To: shimooka@localhost.localdomain
Subject: test
X-PHP-Originating-Script: 500:file.php

のような感じになり、ilia氏のブログにあるとおり

X-PHP-Originating-Script: [PHPスクリプトのownerのuid]:[PHPスクリプトファイル名]

となるようです。実際にuidが501のユーザーにchownして実行すると、先ほどの「500」の部分が「501」となりました。
もう1つのログの方ですが、

mail() on [/path/to/script/file.php:2]: To: shimooka -- Headers:

のようなフォーマットで出力されました。ヘッダを含めた場合、

mail() on [/path/to/script/file.php:2]: To: shimooka -- Headers: From: shimooka@example.com  X-Mailer: test

のようにスペース区切りでヘッダが繋がるようです。