mail(): carriage returns get scrambled

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kAlvaro

    mail(): carriage returns get scrambled

    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
    \r\n

    .... turns into:

    Dear customer,\n\n
    \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
    \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(arr ay("\n", "\r"), array("\\n\n", "\\r"), $headers);
    echo str_replace(arr ay("\n", "\r"), array("\\n\n", "\\r"), $body);
    mai(.....);

    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??

  • Erwin Moller

    #2
    Re: mail(): carriage returns get scrambled

    kAlvaro wrote:
    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
    \r\n
    >
    ... turns into:
    >
    Dear customer,\n\n
    \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
    \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(arr ay("\n", "\r"), array("\\n\n", "\\r"), $headers);
    echo str_replace(arr ay("\n", "\r"), array("\\n\n", "\\r"), $body);
    mai(.....);
    >
    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??
    Hi,

    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

    Regards,
    Erwin Moller

    Comment

    Working...