PHP 8.1.6 Released!

Configurações em Execução

O comportamento dessas funções podem ser modificado pelas configurações do php.ini.

Opções de configuração da função Mail
Nome Padrão Modificável Changelog
mail.add_x_header "0" PHP_INI_PERDIR Disponível desde o PHP 5.3.0.
mail.log NULL PHP_INI_PERDIR Disponível desde o PHP 5.3.0. (PHP_INI_SYSTEM|PHP_INI_PERDIR)
mail.force_extra_parameters NULL PHP_INI_PERDIR Disponível desde o PHP 5.0.0. (PHP_INI_SYSTEM|PHP_INI_PERDIR)
SMTP "localhost" PHP_INI_ALL  
smtp_port "25" PHP_INI_ALL Disponível desde o PHP 4.3.0.
sendmail_from NULL PHP_INI_ALL  
sendmail_path "/usr/sbin/sendmail -t -i" PHP_INI_SYSTEM  
Para mais detalhes e definições dos modos PHP_INI_*, veja Onde uma configuração deve ser definida.

Uma rápida explicação das diretivas de configuração.

mail.add_x_header bool

Adiciona X-PHP-Originating-Script que vai incluir o UID do script seguido pelo nome do arquivo.

mail.log string

O caminho para o arquivo de log que vai armazenar todas as chamadas de log da função mail(). As entradas de log incluirão o caminho completo do script, número da linha, endereço de email To e cabeçalhos.

mail.force_extra_parameters string

Força a adição de parâmetros específicos que serão passados como parâmetros extras para o binário sendmail. Esses parâmetros sempre substituirão o valor do quinto parâmetro da função mail(), mesmo no modo de segurança.

SMTP string

Usado somente no Windows: host name ou endereço IP do servidor SMTP que o PHP deve usar para envio de email com a função mail().

smtp_port int

Usado somente no Windows: Número da porta para conectar no servidor definido com a configuração de SMTP quando enviar email com a função mail(); a porta padrão é 25. Somente disponível após o PHP 4.3.0.

sendmail_from string

Qual endereço de email "From:" deve ser usado na função mail usando o PHP com o Windows. Esta diretiva também define o cabeçalho "Return-Path:".

sendmail_path string

Onde o programa sendmail pode ser encontrado, normalmente em /usr/sbin/sendmail ou /usr/lib/sendmail. configure faz uma tentativa de localizar e definir o padrão, mas se ele falhar, você pode definir aqui.

Sistema que não usam o sendmail devem configurar essa diretiva para a alternativa ao sendmail que o sistema oferece, se houver. Por exemplo, usuário do » Qmail normalmente usam /var/qmail/bin/sendmail ou /var/qmail/bin/qmail-inject.

qmail-inject não requer nehuma opção para o processo funcionar.

Essa diretiva também funciona no Windows. Se definido, smtp, smtp_port e sendmail_from são ignorados e o comando definido é executado.

add a note add a note

User Contributed Notes 9 notes

elitescripts2000 at yahoo dot com
8 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.
php dot net at ii0 dot net
5 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 (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!
Mark Simon
2 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.
mike dot castrodemaria at gmail dot com
8 years ago
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"

change to your own email choice instead .

I hope this helps,
phpnote-mail at revmaps dot no-ip dot org
6 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
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
A Austin
9 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"

The path should work for most linux installations.
blueshibuyadream at gmail dot com
9 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.
11 years ago
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.
rgdobie at conwave dot com dot au
9 years ago
Under Windows, I found sendmail_from needed to be a valid email address which has been defined on the mail server being addressed.
To Top