©
本文档使用 PHP中文网手册 发布
这些函数的行为受 php.ini 中的设置影响。
名字 | 默认 | 可修改范围 | 更新日志 |
---|---|---|---|
mail.add_x_header | "0" | PHP_INI_PERDIR | 自 PHP 5.3.0 起生效 |
mail.log | NULL | PHP_INI_PERDIR | 自 PHP 5.3.0 起生效 |
SMTP | "localhost" | PHP_INI_ALL | |
smtp_port | "25" | PHP_INI_ALL | 自 PHP 4.3.0 起可用 |
sendmail_from | NULL | PHP_INI_ALL | |
sendmail_path | NULL | PHP_INI_SYSTEM |
这是配置指令的简短说明。
mail.add_x_header
bool Add X-PHP-Originating-Script that will include UID of the script followed by the filename.
mail.log
string The path to a log file that will log all mail() calls. Log entries include the full path of the script, line number, To address and headers.
SMTP
string 仅用于 Windows:PHP 在 mail() 函数中用来发送邮件的 SMTP 服务器的主机名称或者 IP 地址。
smtp_port
int 仅用于 Windows:SMTP 服务器的端口号,默认为 25。自 PHP 4.3.0 起可用。
sendmail_from
string 在 Windows 下用 PHP 发送邮件时的“From:”邮件地址的值。该选项同时设置了 “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 都被忽略并运行指定的命令。
[#1] elitescripts2000 at yahoo dot com [2013-12-08 19:52:51]
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.
[#2] mike dot castrodemaria at gmail dot com [2013-06-20 14:00:28]
You can set on apache2 a "per domain" default address in apache conf VirtualHost section too.
Juste add : php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -fno-reply@php.net -Fno-reply"
change to your own email choice instead no-reply@php.net .
I hope this helps,
Mike
[#3] blueshibuyadream at gmail dot com [2013-03-28 12:27:12]
On Darwin OS such as OSX (current one: 10.8.3) you need to add a specific command and option to the sendmail_path constant if you have downloaded and installed a mamp with a stack.
Indeed you can see the required libraries for PHP, Apache, MySQL in "common/lib" folder. The problem is when you run an external command using these libraries, for example "sendmail". It could be a problem if it gets the stack libraries and not the system ones (different versions, etc).
The "env -i" command clean the Stack environment variables and run "sendmail" with the system libraries.
Hope this helps.
[#4] rgdobie at conwave dot com dot au [2013-02-22 06:46:46]
Under Windows, I found sendmail_from needed to be a valid email address which has been defined on the mail server being addressed.
[#5] A Austin [2012-07-11 17:40:45]
For linux you can over-ride the default "From" for the outgoing emails by including in php.ini this line:
sendmail_path = "/usr/sbin/sendmail -t -i -f fromMe@blah.com"
The path should work for most linux installations.
[#6] Robert [2011-04-25 11:09:32]
Despite what this page says about the "SMTP" and "smtp_port" settings being used only under Windows, all Drupal sites use these settings to send email, regardless of which OS they're running in.