Configuration à l'exécution

Le comportement de ces fonctions est affecté par la configuration dans le fichier php.ini.

Options de configuration pour le mail
Nom Défaut Modifiable Historique
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  
Pour plus de détails sur les modes INI_*, reportez-vous à Où une directive de configuration peut être modifiée.

Voici un éclaircissement sur l'utilisation des directives de configuration.

mail.add_x_header bool

Ajoute un en-tête X-PHP-Originating-Script qui inclue l'UID du script, suivi par le nom du fichier.

mail.log string

Le chemin de l'historique de tous les appels à la fonction mail(). Les entrées de l'historique incluent le chemin complet vers le script, le numéro de la ligne, les adresses To ainsi que les en-têtes.

mail.force_extra_parameters string

Permet de forcer l'ajout du paramètre spécifié en tant que paramètre supplémentaire pour sendmail. Ces paramètres prendront la place du cinquième paramètre de la fonction mail().

smtp string

Sous Windows seulement : nom de l'hôte ou adresse IP du SMTP que PHP doit utiliser pour envoyer un mail avec la fonction mail().

smtp_port int

Sous Windows seulement : numéro de port à utiliser pour se connecter au serveur SMTP lors de l'envoi de mail avec la fonction mail(); par défaut, c'est 25.

sendmail_from string

Sous Windows seulement : valeur du champ "From:" qui doit être utilisée lors de l'envoi de mail via SMTP (uniquement sous Windows). Cette directive définira également l'en-tête "Return-Path:".

sendmail_path string

Localisation du programme sendmail : habituellement /usr/sbin/sendmail ou /usr/lib/sendmail. configure essaye de repérer la présence de sendmail par lui-même, et affecte ce résultat par défaut. En cas de problème de localisation, vous pouvez établir une nouvelle valeur par défaut ici.

Tout système n'utilisant pas sendmail doit établir cette directive à la valeur chemin du programme de substitution qui remplace le serveur de mail, si celui-ci existe. Par exemple, les utilisateurs de » Qmail peuvent la définir à /var/qmail/bin/sendmail ou /var/qmail/bin/qmail-inject.

qmail-inject ne requiert aucune option pour traiter correctement le mail.

Cette directive fonctionne également sous Windows. Si elle est définie, smtp, smtp_port et sendmail_from sont ignorés et la commande spécifiée est exécutée.

add a note add a note

User Contributed Notes 8 notes

up
32
elitescripts2000 at yahoo dot com
10 years ago
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.
up
3
jscholz at wisc dot edu
2 years ago
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.
up
-2
php dot net at ii0 dot net
7 years ago
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!
up
-6
Mark Simon
5 years ago
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.
up
-15
A Austin
12 years ago
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.
up
-15
phpnote-mail at revmaps dot no-ip dot org
8 years ago
setting return path:

Return-path header does not work because it is not part of smtp.

on *nix -f may be set on the mail command
alternatively
some MTAs accept mbox-style "From " header on the first header line
note: no colon after "From" , must be the first header line
or  you may be able to re-configure you MTA to interpret return-path headers

-f is the most reliable method but it may mean that you can't set any other command-line option due to shell escaping problems.

also note that email formatting requirements differ between windows and everything else. sendmail expects only \n line-endings
up
-20
blueshibuyadream at gmail dot com
11 years ago
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.
up
-8
torsar at gmail dot com
1 year ago
Ненавижу всякие денверы и ёбн серверы.

У меня голый апач на винде 10 и на нем 6 версий пхп от 5.6 до самой последней. :)
Все устанавливается и конфигиться за минуты. :)
Все версии пхп конфигяться отдельно и работают одновременно. На разных виртуальных хостах и портах.
Не надо ничего переключать и перезапускать.

У меня еще есть виртуальная машина(WmVare) c FreeBSD 13.
Там, например, Redis.
С пхп на винде все работает.

Так вот вопрос:
можно ли юзать sendmail с виртуальной машины на юниксе
в пхп на винде?
Было бы замечательно!!!

Зы в идеале хочу перенести апач с пхпями на виртуальную машину с юникс.
А загружать пхп скрипты с браузера под виндой.
Там уже установлен апач и последняя версия пхп.
И еще perl и Go. (Зачем не знаю. :) Было по приколу поковырять конфиги и понастраивать :) )

Но пока не разобрался как в юниксах подтянуть к голому апачу несколько версий пхп. :(
To Top