mail(): carriage returns get scrambled

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I wrote a custom class that uses mail() to send messages. My class
takes care that all lines end in \r\n as required by RFCs.

I have two Red Hat 9 servers (development + production). My development
server works fine; however, I've noticed that in my production server
extra line ending chars are added randomly to outgoing messages. I
didn't notice until now because Outlook handles it fine. On the
contrary, most other mail clients think these extra line feeds are
empty lines. As a result, headers pop into message body and message
body itself gets extra blanks line.

As I said, it looks random to me--I can't find any pattern:

Dear customer,\r\n

... turns into:

Dear customer,\n\n

I looks like \r is replaced by \n... But:

Content-Type: text/plain; charset=iso-8859-1\r\n
Content-Transfer-Encoding: 8bit\r\n

... turns into:

Content-Type: text/plain; charset=iso-8859-1\r\n
Content-Transfer-Encoding: 8bit\n\n

(the same input \r\n gets two different outputs).

I check both body and custom headers just before calling mail():

echo str_replace(array("\n", "\r"), array("\n\n", "\r"), $headers);
echo str_replace(array("\n", "\r"), array("\n\n", "\r"), $body);

At this point, everything's OK.

My first candidate was mod_security, yet disabling it makes no change.
We don't have a virus scanner. Mail server is postfix.

Do you have any hint??

Re: mail(): carriage returns get scrambled

kAlvaro wrote:

Quoted text here. Click to load it


Not sure about the RFC, but I always just used the \n alone, without the \r,  
and that never gave any troubles. :-/
Maybe give that a try.

just my 2 cent  

Erwin Moller

Site Timeline