実行時設定
php.ini の設定により動作が変化します。
名前 | デフォルト | 変更可能 | 変更履歴 |
---|---|---|---|
mail.add_x_header | "0" | INI_PERDIR |
|
mail.log | NULL | INI_SYSTEM |INI_PERDIR |
|
mail.force_extra_parameters | NULL | INI_SYSTEM |INI_PERDIR |
|
SMTP | "localhost" | INI_ALL |
|
smtp_port | "25" | INI_ALL |
|
sendmail_from | NULL | INI_ALL |
|
sendmail_path | "/usr/sbin/sendmail -t -i" | INI_SYSTEM |
以下に設定ディレクティブに関する 簡単な説明を示します。
-
mail.add_x_header
bool -
X-PHP-Originating-Script
を追加します。 それはスクリプトの UID を含み、その後にファイル名が続きます。 -
mail.log
string -
ログファイルへのパス。mail() がコールされるたびにこのファイルに記録します。 ログに含まれる内容は、スクリプトのフルパスと行番号、そして
To
アドレスとヘッダです。 -
mail.force_extra_parameters
string -
指定したパラメータを、sendmail バイナリへの追加パラメータとして強制的に渡します。 これらのパラメータは、常に mail() の第 5 パラメータの値を上書きします。
-
SMTP
string -
Windows 環境のみで使用されます: mail() 関数でメールを送信する際に使用する SMTP サーバーのホスト名または IP アドレス。
-
smtp_port
int -
Windows 環境のみで使用されます:
SMTP
設定で指定したサーバーに接続するポート番号で、 デフォルトは 25 です。 -
sendmail_from
string -
SMTP 経由で直接送信されるメールにおいて
"From:"
に使用するメールアドレスを指定します(Windows環境のみ)。 このディレクティブは、"Return-Path:"
ヘッダも設定します。 -
sendmail_path
string -
sendmail プログラムを探すパスを指定します。 通常、/usr/sbin/sendmail または /usr/lib/sendmail です。 configure は、このパスを探し、 デフォルト値として設定しますが、 これで上手くいかない場合にはこのオプションで設定する必要があります。
sendmail を使用していないシステムは、 使用するメールシステムが提供する sendmail のラッパー/代替品を、 必要に応じてこのディレクティブに設定する必要があります。例えば、» Qmail ユーザーは、通常 /var/qmail/bin/sendmail または /var/qmail/bin/qmail-inject に設定します。
qmail-inject では、 メールを正しく処理するためのオプション設定は不要です。
このディレクティブは Windows 環境でも動作します。指定された場合は smtp および smtp_port・ sendmail_from の値は無視され、 ここで指定したコマンドが実行されます。
User Contributed Notes 4 notes
On Ubuntu 13.04, not sure of the other Distros.
If you simply uncomment the default:
sendmail_path = "sendmail -t -i"
Your mail() functions will all fail. This is because, you should place the FULL PATH (i.e. /usr/sbin/sendmail -t -i )
The documentation states PHP tries it's best to find the correct sendmail path, but it clearly failed for me.
So, always enter in the FULLPATH to sendmail or you may get unexpected failing results.
As a secondary note: Those that just want to ENFORCE the -f parameter, you can do so in php.ini using:
mail.force_extra_parameters = -fdo_not_reply@domain.tld
You can leave the sendmail path commented out, it will still use the defaults (under UNIX -t -i options which if you look them up are very important to have set)....
But, now there is no way to change this, even with the 5th argument of the mail() function. -f is important, because if NOT set, will be set to which ever user the PHP script is running under, and you may not want that.
Also, -f sets the Return-Path: header which is used as the Bounce address, if errors occur, so you can process them. You you can not set Return-Path: in mail() headers for some reason... you could before. Now you have to use the -f option.
The documentation should be made clear that sendmail does NOT default to -t -i when using just /usr/sbin/sendmail. You literally need to specify the options.
I know this might seem like a no-brainer but I wasted hours trying to get mail() to work only to discover that the sendmail program is NOT passed -t and -i by default as stipulated in the documentation.
If anyone gets this cryptic error message in the PHP error logs:
"sh: -t: command not found"
after upgrading from PHP 5.4, this may be the solution for you.
I upgraded PHP from 5.4 to 5.6 and all our mail() functionality suddenly broke, with no useful error logging.
If this is you, and you've been using ini_set() to set the "sendmail_path" then note that even though it's apparently not mentioned in the upgrade documentation -- or anywhere else I could find on php.net (or a dozen forums) -- you'll now need to go set the sendmail_path in your php.ini file; it is now ignored if you use ini_set() to specify a path to the sendmail binary on the fly.
So, just specify "sendmail_path" in php.ini instead. That's all there is to it -- that fixed all the mail() functionality for us.
Hope this little note saves someone else as much time as I spent troubleshooting and researching. Cheers!
It is worth reiterating that, as stated above, sendmail_path also works for Windows, overriding other Windows SMTP settings.
The comment in php.ini, “For Unix only”, does not make that clear.
This makes it relatively easy to substitute a fake sendmail program or even a shell script/batch file to save mail to a text file.
I use this technique when teaching or testing in PHP.