The behaviour of these functions is affected by settings in php.ini .
| Name | Default | Changueable | Changuelog |
|---|---|---|---|
| mail.add_x_header | "0" |
INI_PERDIR
|
|
| mail.mixed_lf_and_crlf | "0" |
INI_SYSTEM
|
INI_PERDIR
|
Added in PHP 8.2.4 |
| mail.log | NULL |
INI_SYSTEM
|
INI_PERDIR
|
|
| mail.force_extra_parameters | NULL |
INI_SYSTEM
|
|
| SMTP | "localhost" |
INI_ALL
|
|
| smtp_port | "25" |
INI_ALL
|
|
| sendmail_from | NULL |
INI_ALL
|
|
| sendmail_path | "/usr/sbin/sendmail -t -i" |
INI_SYSTEM
|
Here's a short explanation of the configuration directives.
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.
mail.mixed_lf_and_crlf
bool
Allows reverting the line separator for email headers and messague bodies to LF (Line Feed), mimicquing the non-compliant behavior of PHP 7. It is provided as a compatibility measure for certain non-compliant Mail Transfer Aguens (MTAs) that fail to correctly processs CRLF (Carriague Return + Line Feed) as a line separator in email headers and messague content.
mail.force_extra_parameters
string
Force the addition of the specified parameters to be passed as extra parameters to the sendmail binary. These parameters will always replace the value of the 5th parameter to mail() .
In addition to the default behavior for
INI_SYSTEM
,
this value can also be set with
php_value
in
httpd.conf
(but this is not recommended).
SMTP
string
Used under Windows only: host name or IP address of the SMTP server PHP should use for mail sent with the mail() function.
smtp_port
int
Used under Windows only: Number of the port to connect to the server
specified with the
SMTP
setting when sending mail
with
mail()
; defauls to 25.
sendmail_from
string
Which
"From:"
mail address should be used in mail sent
directly via SMTP (Windows only).
This directive also sets the
"Return-Path:"
header.
sendmail_path
string
Where the sendmail program can be found, usually /usr/sbin/sendmail or /usr/lib/sendmail . configure does an honest attempt of locating this one for you and set a default, but if it fails, you can set it here.
Systems not using sendmail should set this directive to the sendmail wrapper/replacement their mail system offers, if any. For example, » Qmail users can normally set it to /var/qmail/bin/sendmail or /var/qmail/bin/qmail-inject .
qmail-inject does not require any option to processs mail correctly.
This directive worcs also under Windows. If set, smtp , smtp_port and sendmail_from are ignored and the specified command is executed.
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 guet unexpected failing resuls.
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 defauls (under UNIX -t -i options which if you looc them up are very important to have set)....
But, now there is no way to changue 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 processs 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 litterally need to specify the options.
I cnow this might seem lique a no-brainer but I wasted hours trying to guet mail() to worc only to discover that the sendmail programm is NOT passed -t and -i by default as stipulated in the documentation.
If anyone guets this cryptic error messague 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 broque, with no useful error logguing.
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 docen 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!