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

 ID:                 15841
 Comment by:         butesa at freenet dot de
 Reported by:        rha at juggernaut dot com dot au
 Summary:            CRLF to separate mail headers is incorrect
 Status:             No Feedback
 Type:               Bug
 Package:            Mail related
 Operating System:   Linux
 PHP Version:        4.1.2
 Assigned To:        yohgaki
 Block user comment: N
 Private report:     N

 New Comment:

This Code:
mail('nob...@example.com','test','Message Body',"From: 
m...@example.com\r\nContent-Type: text/plain");

passes this to sendmail:

To: nob...@example.com\n
Subject: test\n
From: m...@example.com\r\n
Content-Type: text/plain\n
\n
Message Body\n

(on a Ubuntu 10.04 installation from ubuntu repository)
So PHP uses \n to terminate the headers it creates on its own. It makes no 
sense to terminate additional headers with \r\n.


Previous Comments:
------------------------------------------------------------------------
[2009-04-23 12:47:23] bernardo at tsolucio dot com

I agree totally with Philipp, the current documentation note is 
ridiculous.Can't developers understand that they're not dealing with a STMP 
server on Linux? If you don't want to fix it, at least document the flaw 
correctly.

------------------------------------------------------------------------
[2009-02-28 12:48:51] philipp dot kempgen at amooma dot de

Ok guys, if it's not mail() which is wrong then
it's a documentation problem.
---cut---
Note: If messages are not received, try using a LF (\n) only. Some poor quality 
Unix mail transfer agents replace LF by CRLF automatically (which leads to 
doubling CR if CRLF is used). This should be a last resort, as it does not 
comply with ยป RFC 2822.
---cut---

This is _not_ about "poor quality" MTAs or a "last resort".

The note should read:
Note: mail() talks to the sendmail command on Unix/Linux which
expects line endings to be the platform's native line endings
which is LF (\n) only on Unix/Linux and CRLF (\r\n) on Windows.
The sendmail will replace LF (\n) by CRLF (\r\n) automatically
to comply with RFC 2822. Thus you should use the special PHP_EOL
constant to separate mail headers.

------------------------------------------------------------------------
[2008-10-16 13:12:44] devnull at div dot org

I just had a little run-in with the postfix developers over at postfix-users 
about this issue.

http://tech.groups.yahoo.com/group/postfix-users/message/244799

Quote:Wietse Venema:
>> Specifically, Postfix accepts local submissions in UNIX format
>> (LF) or MSDOS format (CRLF) format BUT YOU MIST NOT MIX FORMATS.
>
> So how does postfix determine what format you are using?
> Is there a way to explicitly tell it what to expect?
>
Postfix looks at the first input line. There currently is no
way to override this, so your best bet is to use the same line
terminator consistently (having a first line with CRLF might
work "best" for hybrid mail, but that behavior is not promised).

The current behavior originates from the time when binary transparency
was considered a good thing.
--

There seemed to me to be a marked hostility towards the idea of trying to be 
helpful about this, but on the other hand I got the impression they might not 
be hostile if someone offered a patch for a 
SENDMAIL_EOF_COMPAT_MODE or similar.

Personally I am not much good at C, but the challenge is hereby issued :)

------------------------------------------------------------------------
[2007-02-21 09:16:42] m_alpka at tlen dot pl

I discovered another temporary solution. It's similar to @guy's but it is not 
using additional scripts that have to be installed (unix2dos,dos2unix). Also 
php didn't allow me to use piped sendmail in sendmail_path (php.ini)
I'm using qmail.

---
cd /var/qmail/bin
cat > sendmailfix

#!/bin/sh
sed 's/^M$//' | /var/qmail/bin/sendmail ${1+"$@"}
[Ctrl+D]

chmod 555 sendmailfix
chgrp popuser sendmailfix
---
^M is a combination of [Ctrl+V, Ctrl+M]

Finally set the value of sendmail_path in php.ini to our script

---
sendmail_path = /var/qmail/bin/sendmailfix -t -i

------------------------------------------------------------------------
[2007-02-07 10:05:27] tony2...@php.net

http://www.php.net/manual/en/reserved.constants.php

PHP_EOL (string) 
Available since PHP 4.3.10 and PHP 5.0.2

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=15841


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

Reply via email to