Edit report at http://bugs.php.net/bug.php?id=44170&edit=1

 ID:                 44170
 Comment by:         anrdaemon at freemail dot ru
 Reported by:        marijn at monomelodies dot nl
 Summary:            mail() function arguments ambiguity
 Status:             Open
 Type:               Feature/Change Request
 Package:            Mail related
 Operating System:   *
 PHP Version:        5.2.6
 Block user comment: N
 Private report:     N

 New Comment:

IMO, the mail() "to" parameter should represent mail envelope RCPT-TO
value, not the mail "To" header. And should never be substituted into
header "To:" field if it not defined by user.

Else it defeats the use of mail() function, when you are writing, i.e.,
a mailing list handler.


Previous Comments:
------------------------------------------------------------------------
[2008-02-19 14:39:15] marijn at monomelodies dot nl

Description:
------------
The docs for the mail() function state the first parameter ($to) as
being obligatory. They also state that "the formatting of this string
must comply with ยป RFC 2822".

This would lead me to expect that passing a string not containing a
valid address would cause a warning or at least a notice. This isn't
so.

While technically I'm fairly sure this is correct behaviour (AFAICT RFC
2822 states that either To, Cc or Bcc should be included, so leaving
*out* To shouldn't be a problem and in fact isn't, and non-email
addresses are also supported) the docs suggest that under PHP it is in
fact illegal.

I would expect that passing NULL or an empty string would result in the
entire To: field being omitted in the headers (it's now in fact empty,
which doesn't seem to conform to RFC 2822 which says that if you *do*
include any such header it should contain a comma-separated list of at
*least* 1 address). Whether or not a notice should follow something that
doesn't appear to be an emailaddress is a matter for debate - I'd
personally leave regexing to the users of the function, but then the
manual isn't correct.



So, actually it's something of a bug/feature in the mail() function as
well I believe, and passing NULL as the first parameter should cause the
To-header to be omitted.

But since including a To-header seems like good form mostly the docs
are, I feel, somewhat incomplete in this respect.

Reproduce code:
---------------
<?php



mail(

        NULL,

        'test',

        NULL,

        <<<EOT

Bcc: mar...@monomelodies.nl



test



EOT

);

Expected result:
----------------
Depending on how you feel about $to being obligatory, either a
better-formed email being sent, or a notice or even warning thrown by
PHP.

Actual result:
--------------
[...snip...]

To:           <-- violates RFC 2822

Subject: test



test


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=44170&edit=1

Reply via email to