note 126334 added to function.mail
| From: | atesin at main dot php dot net | Date: | Thu, 12 Aug 2021 08:07:25 +0000 |
| Subject: | note 126334 added to function.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216776@lists.php.net to get a copy of this message | ||
HOW PHP MAIL() WORKS INTERNALLY, more or less, according some tests i did
imagine php is running with uid 33 when reaches a mail() function like this
---- /my/htdocs/mailer-script.php line 69 ----
$was_sent = mail(
'Alice <alice@wonder.land>, white-rabbit@endless.cave',
'Invitation',
"Hi, you are cordially invited to drink a cup of tea at my house\ntomorrow at sunset",
"Some-Header: foo\r\nOther-Header: bar", // can also be an associative array of
'Header' => 'Value'
'param1 param2');
----
then look for ini options like this (all optional, on any operating system)
---- ini options ----
; path to mail sender command + arguments, if omitted will defaults to NULL
sendmail_path = '/bin/sendmail-esque arg1 arg2'
; the From header, can be also set in sendmail but make sure it SENDS ONE
sendmail_from = 'Mad Hatter <hatter@house.forest>'
; recommended to not being blind, look at file permissions
mail.log = '/var/log/php/mail.log'
; adds an originating script header to send php mail internals (security sensitive)
mail.add_x_header = on
; outgoing mail server address, if omitted will defaults to "localhost"
;SMTP = 'localhost'
; server tcp port, if omitted will defaults to port 25
;smtp_port = 25
----
then craft a message like this (please avoid duplicated headers)
---- mail message ----
From: Mad Hatter <hatter@house.forest>
To: Alice <alice@wonder.land>, white-rabbit@endless.cave
Subject: Invitation
Some-Header: foo
Other-Header: bar
X-PHP-Originating-Script: 33:mailer-script.php
Hi, you are cordially invited to drink a cup of tea at my house
tomorrow at sunset
----
then APPEND this log line
---- /var/log/php/mail.log ----
[<date> <time> <zone>] mail() on [/my/htdocs/mailer-script.php:69]: <all
headers joined...>
----
THEN IF (sendmail_path is not empty, AND file is found, AND has +rx permissions):
- craft and run this shell command
---- shell ----
/bin/sendmail-esque arg1 arg2 param1 param2
----
- send the crafted message to its standard input
- wait the program to exit
- pass last exit code to mail() return
OR ELSE (i.e. sendmail bin not run) (not sure about these):
- try to internally open an smtp connection (with fsockopen()?)
- send the message directly and wait for connection to close
- pass last socket status to mail() return
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 201.241.15.102)
----
Manual Page -- https://php.net/manual/en/function.mail.php
Edit -- https://main.php.net/note/edit/126334
Del: integrated -- https://main.php.net/note/delete/126334/integrated
Del: useless -- https://main.php.net/note/delete/126334/useless
Del: bad code -- https://main.php.net/note/delete/126334/bad+code
Del: spam -- https://main.php.net/note/delete/126334/spam
Del: non-english -- https://main.php.net/note/delete/126334/non-english
Del: in docs -- https://main.php.net/note/delete/126334/in+docs
Del: other reasons-- https://main.php.net/note/delete/126334
Reject -- https://main.php.net/note/reject/126334
Search -- https://main.php.net/manage/user-notes.php