PHP 8.5.0 Alpha 1 available for testing

Configuración en tiempo de ejecución

El comportamiento de estas funciones se ve afectado por la configuración de php.ini.

Opciones de configuración para el correo
Nombre Por defecto Cambiable Historial de cambios
mail.add_x_header "0" INI_PERDIR  
mail.mixed_lf_and_crlf "0" INI_SYSTEM|INI_PERDIR Disponible a partir de PHP 8.2.4
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  
Para más detalles y definiciones de los modos de INI_*, vea Dónde una directiva de configuración puede ser modificada.

He aquí una breve explicación de las directivas de configuración.

mail.add_x_header bool

Se añade un encabezado X-PHP-Originating-Script que incluye el UID del script, seguido por el nombre del fichero.

mail.log string

La ruta del registro de todos los llamados a la función mail(). Las entradas del registro incluyen la ruta completa hacia el script, el número de la línea, las direcciones To así como los encabezados.

mail.mixed_lf_and_crlf bool

Permite volver al indicador de fin de línea para los encabezados de correo electrónico y los cuerpos de mensaje en LF (Line Feed), imitando el comportamiento no conforme de PHP 7. Se proporciona como medida de compatibilidad para ciertos Agentes de Transferencia de Correo (MTA) no conformes que fallan al tratar correctamente CRLF (Retorno de carro + Line Feed) como indicador de fin de línea en los encabezados de correo electrónico y el contenido de los mensajes.

mail.force_extra_parameters string

Permite forzar la adición del parámetro especificado como parámetro adicional para sendmail. Estos parámetros reemplazarán al quinto parámetro de la función mail().

smtp string

Solo en Windows: nombre del host o dirección IP del SMTP que PHP debe utilizar para enviar un correo con la función mail().

smtp_port int

Solo en Windows: número de puerto a utilizar para conectarse al servidor SMTP al enviar correo con la función mail(); por omisión, es 25.

sendmail_from string

Solo en Windows: valor del campo "From:" que debe ser utilizado al enviar correo vía SMTP (solo en Windows). Esta directiva definirá también el encabezado "Return-Path:".

sendmail_path string

Localización del programa sendmail: habitualmente /usr/sbin/sendmail o /usr/lib/sendmail. configure intenta detectar la presencia de sendmail por sí mismo, y asigna este resultado por omisión. En caso de problemas de localización, puede establecerse un nuevo valor por omisión aquí.

Todo sistema que no utilice sendmail debe establecer esta directiva al camino del programa de sustitución que reemplaza al servidor de correo, si aquel existe. Por ejemplo, los usuarios de » Qmail pueden definirla a /var/qmail/bin/sendmail o /var/qmail/bin/qmail-inject.

qmail-inject no requiere opciones para tratar correctamente el correo.

Esta directiva funciona también en Windows. Si está definida, smtp, smtp_port y sendmail_from son ignorados y se ejecuta el comando especificado.

add a note

User Contributed Notes 3 notes

up
27
elitescripts2000 at yahoo dot com
11 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
2
jscholz at wisc dot edu
3 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
1
php dot net at ii0 dot net
8 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!
To Top