server is running qmail.

my php mail() generated html email was messed up

There were messages like this in the html email body.

MIME-Version: 1.0 X-NAS-Language: English X-NAS-Bayes: #0: 7.79858E-129; #1: 1 X-NAS-Classification: 0 X-NAS-MessageID: 4836 X-NAS-Validation: {5753C5C2-D7E9-4323-AA66-9A638F2E5C0A}

What is the problem? Thanks!

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

    OK, I got the reason of the problems. Blame qmail.

    --
    Last November the mail documentation was changed from saying:
    "Multiple extra headers are separated with a newline."
    to:
    "Multiple extra headers are separated with a carriage return and
    newline. Note: You must use \r\n to seperate headers, although some Unix
    mail transfer agents may work with just a single newline (\n)."

    This change is inaccurate. Line breaks in headers should be the native
    line endings for the system on which PHP is running.

    The mail() function is not talking to an SMTP server, so RFC2822 does
    not apply here. mail() is talking to a command line program on the local
    system, and it is reasonable to expect that program to require
    system-native line breaks.

    Use of CRLF is known to break qmail systems where no conversion of line
    breaks occurs on the input data. In this case using CRLF causes all but
    the first extra header to appear in the message body (CRLF is
    interpreted as two line breaks).

    Possibly the best resolution to this problem would be for the mail()
    function to convert any line breaks in arg 4 into the system's native
    line breaks.

    --

    Thanks!

      The solution above link suggest is change \r\n to \n.

      But php ducumentation discouraged it. So are there any solutions that \r\n works with qmail on freebsd?

      Note: When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.
      Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.

      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.

      So my question is

      I have dozens sites use hundreds times mail(). I don't want to change them to meet the qmail standard. Later on, if I move them to server only use sendmail, then what?

        OK, tested and confirmed.

        If I change them to \n, all works fine. But if \r\n. Then depends on pop mail server and your mail client. Some works fine, some not. For example,

        1) I am using outlook express to receive these test html emails. From one hosting server, it was fine. From another, it was broken.

        2) on hotmail, all fine. But on gmail, then the html emails broken.

        Now, my final questions are

        1) Do I need to change all my email headers from \r\n to \n? no way to be portable to both?

        2) If I change all my headers from \r\n to \n, I will have troubles if the site will be host on windows platform, right? If I am staying on Unix, such as unix and sendmail, i will still be fine, right?

        3) It seems that if I am on unix, I should use \n. But I was on unix and sendmail before, why I am fine? So sendmail somehow takes care of this, did qmail have a way to take care of this issue too? Instead of I need to dig out to change all the pages with this.

        4) Could someone give me a regular expression script to mass search files in the unix folder

        /home/www

        and repalce all the codes \r\n with \n

        ?

        except in the mail headers codes, I cannot remember in any other places that I used \r\n?

        5) or to be on the safe side, could anyone write me a regular expression for freebsd unix system

        to mass search files in the unix folder

        /home/www

        and search all the strings start with $headers, and has \r\n in it, replace the \r\n with \n.

        Thanks a lot. I can try regular expression myself, but I am not a regular expression expert and I am afraid that if I miss something, I may mess up the files to a degree that I cannot fix.

        Of course, if anyone can help me with the regular expression, I will test it myself first and back up the whole folders too before I apply them.

        Thanks!

          OK, I found a soultion from this link, the last post.

          Any better ideas? Will this solution have any new problems? such as performance, and load of the server? Can any unix experts tell me about what I should be aware if I use this solution? Thanks!

          The following script will tell qmail don't auto-replace \n with \r\n, right? except in the php mail() headers, will there be any place we need qmail auto replace \n with \r\n? Then that will not work now?

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

          [21 Feb 2007 9:16am UTC] m_alpka at tlen dot pl
          I discovered another temporary solution. It's similar to @'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

            Write a Reply...