I've encountered difficulties utilising the mail() function properly
under a NIX environments while conforming to RFC 2822. There two
specific issues, one is a code problem the other a documentation
issue they are intertwined so I thought best run it by here and see
that people understand the issue before I head to the bug tracker.
As you are no doubt aware mail() operates using the system sendmail
interface under NIX environments, and under Windows it either utilises a
sendmail binary or more commonly the SMTP feature. The problem stems
from confusion and inappropriate application of the SMTP standards to
the sendmail interface.
Under a NIX environment the sendmail interface operates taking an e-mail
message constructed using the system line ending, LF. I've confirmed
this applies to the Postfix sendmail interface , and could ask other
Under Windows either the sendmail binary or SMTP is utilised. The
correct line endings for SMTP are certainly CR-LF, sendmail I guess
could be either.
The documentation mentions to use CR-LF as the line endings for the
$additional_headers parameters whilst the function implementation
utilises LFs  which results in a mix of line endings, which is worse
than incorrect line endings. There is a 7 year old bug open about this
inconsistency  and as of yet nobody has fixed it, I hope this can be
The second issue I have is quite a show stopper with regards to properly
formatted emails under the NIX environment; email headers maybe no
longer than 998 characters but the advised cut off is 78, a long
header should be folded over two lines with some white space
indentation.  As the To and Subject headers are populated from the
function arguments of the same name they pass through additional checks
over the other headers. The problem arises with the SKIP_LONG_HEADER_SEP
macro  which only skips over the SMTP standard of CR-LF-WSP and not
LF-WSP required for NIX sendmail as a consequence the LF is replace with
a space effectively unfolding the folded line. It is therefore
impossible to correctly create an email using mail() with a large number
of recipients or a long subject, the effective limit of text shrinks
when encoding is used for non ASCII characters as well.
Can anyone provide me with any insight?