mail() - message lines <= 70 chars

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

    #1

    mail() - message lines <= 70 chars

    I'm using PHP version 4.4.3.

    The manual page for PHP's mail() function (URL below) says that for the
    message (IE. email body) "Each line should be separated with a LF (\n).
    Lines should not be larger than 70 characters."



    To see what happened I just sent an email using mail() with one of its
    lines exactly 100 chars. It was sent perfectly by sendmail as a line of
    100 chars and no newline. PHP did not seem to mind at all.

    Why the limitation of <= 70 chars per line, and why does my version of PHP
    not seem to care?

    Thanks all.
  • John Dunlop

    #2
    Re: mail() - message lines &lt;= 70 chars

    Matthew:
    The manual page for PHP's mail() function (URL below) says that for the
    message (IE. email body) "Each line should be separated with a LF (\n).
    Should be CRLF.


    Lines should not be larger than 70 characters."
    Should be 78.



    --
    Jock

    Comment

    • Matthew

      #3
      Re: mail() - message lines &lt;= 70 chars

      John Dunlop emailed this:
      Matthew:
      >
      >The manual page for PHP's mail() function (URL below) says that for the
      >message (IE. email body) "Each line should be separated with a LF (\n).
      >
      Should be CRLF.
      >

      >
      >Lines should not be larger than 70 characters."
      >
      Should be 78.
      >

      >
      --
      Jock
      Thanks.

      Why do the long lines of 100 chars work for me anyway?

      Comment

      • Rik Wasmus

        #4
        Re: mail() - message lines &lt;= 70 chars

        On Thu, 22 Nov 2007 18:13:52 +0100, Matthew <matthew@spamki ller.comwrote:
        John Dunlop emailed this:
        >Matthew:
        >>The manual page for PHP's mail() function (URL below) says that for the
        >>message (IE. email body) "Each line should be separated with a LF (\n).
        > Should be CRLF.
        > http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1
        >>
        >>Lines should not be larger than 70 characters."
        > Should be 78.
        > http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1.1
        >
        Why do the long lines of 100 chars work for me anyway?
        1. PHP doesn't check it: you, as the programmer, should take care of it.
        2. Most email clients/servers ar robust enough to handle more characters.
        The fact that almost all can is still not a reason to let the number of
        characters slide though.
        --
        Rik Wasmus

        Comment

        • Matthew

          #5
          Re: mail() - message lines &lt;= 70 chars

          Rik Wasmus emailed this:
          On Thu, 22 Nov 2007 18:13:52 +0100, Matthew <matthew@spamki ller.comwrote:
          >John Dunlop emailed this:
          >>Matthew:
          >>>The manual page for PHP's mail() function (URL below) says that for the
          >>>message (IE. email body) "Each line should be separated with a LF (\n).
          >> Should be CRLF.
          >> http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1
          >>>
          >>>Lines should not be larger than 70 characters."
          >> Should be 78.
          >> http://www.apps.ietf.org/rfc/rfc2822.html#sec-2.1.1
          >>
          >Why do the long lines of 100 chars work for me anyway?
          >
          1. PHP doesn't check it: you, as the programmer, should take care of it.
          2. Most email clients/servers ar robust enough to handle more
          characters. The fact that almost all can is still not a reason to let
          the number of characters slide though.
          Thanks Rik. I'll just add a newline every 70 chars then.

          Comment

          • Toby A Inkster

            #6
            Re: mail() - message lines &lt;= 70 chars

            Matthew wrote:
            Thanks Rik. I'll just add a newline every 70 chars then.
            PHP has a function called wordwrap() that may be useful for you.

            --
            Toby A Inkster BSc (Hons) ARCS
            [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
            [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 17:53.]

            It'll be in the Last Place You Look

            Comment

            • C. (http://symcbean.blogspot.com/)

              #7
              Re: mail() - message lines &lt;= 70 chars

              On 22 Nov, 16:47, John Dunlop <j...@dunlop.na mewrote:
              Matthew:
              >
              The manual page for PHP's mail() function (URL below) says that for the
              message (IE. email body) "Each line should be separated with a LF (\n).
              >
              Should be CRLF.
              >

              >
              Lines should not be larger than 70 characters."
              >
              Should be 78.
              >

              >
              --
              Jock
              No - that's SMTP which is a specific transport mechanism for email
              (actually its a whole family of protocols but lets not go there) its
              up to the MUA ('mail' command on Unix or the SMTP implementation
              within PHP for |MSWin) to **convert** the message to a suitable format
              for the MTA, which may in turn encode the message in a different
              format depending on the carrier protocol.

              Perhaps historically the SMTP implementation in PHP couldn't
              accomodate this.

              If you sniff the SMTP connection you'll see that long lines do get
              wrapped - but the original message is restored when it comes out the
              MUA at the other end.

              C.

              Comment

              • John Dunlop

                #8
                Re: mail() - message lines &lt;= 70 chars

                C. (http://symcbean.blogspot.com/):
                No - that's SMTP which is a specific transport mechanism for email
                (actually its a whole family of protocols but lets not go there) its
                up to the MUA ('mail' command on Unix or the SMTP implementation
                within PHP for |MSWin) to **convert** the message to a suitable format
                for the MTA, which may in turn encode the message in a different
                format depending on the carrier protocol.
                Right.
                Perhaps historically the SMTP implementation in PHP couldn't
                accomodate this.
                >
                If you sniff the SMTP connection you'll see that long lines do get
                wrapped - but the original message is restored when it comes out the
                MUA at the other end.
                I wonder where PHP's figure 70 came from? If long lines do get
                wrapped but you still recommended a limit, would you not recommend
                78, in line with the transfer protocol?

                On the other note, line endings seem a bit messy: \n for the message
                body but \r\n for headers, whereas the transfer protocol demands \r\n
                across the board. Then, I suppose, the whole business of line ending
                conventions is messy.

                --
                Jock

                Comment

                • Matthew

                  #9
                  Re: mail() - message lines &lt;= 70 chars

                  Toby A Inkster emailed this:
                  Matthew wrote:
                  >
                  >Thanks Rik. I'll just add a newline every 70 chars then.
                  >
                  PHP has a function called wordwrap() that may be useful for you.
                  Thanks Toby. I already found it looking through the string functions in
                  the manual for an appropriate function to use.

                  Cheers.

                  Comment

                  • Matthew

                    #10
                    Re: mail() - message lines &lt;= 70 chars

                    John Dunlop emailed this:
                    C. (http://symcbean.blogspot.com/):
                    >
                    >No - that's SMTP which is a specific transport mechanism for email
                    >(actually its a whole family of protocols but lets not go there) its
                    >up to the MUA ('mail' command on Unix or the SMTP implementation
                    >within PHP for |MSWin) to **convert** the message to a suitable format
                    >for the MTA, which may in turn encode the message in a different
                    >format depending on the carrier protocol.
                    >
                    Right.
                    >
                    >Perhaps historically the SMTP implementation in PHP couldn't
                    >accomodate this.
                    >>
                    >If you sniff the SMTP connection you'll see that long lines do get
                    >wrapped - but the original message is restored when it comes out the
                    >MUA at the other end.
                    >
                    I wonder where PHP's figure 70 came from? If long lines do get
                    wrapped but you still recommended a limit, would you not recommend
                    78, in line with the transfer protocol?
                    >
                    On the other note, line endings seem a bit messy: \n for the message
                    body but \r\n for headers, whereas the transfer protocol demands \r\n
                    across the board. Then, I suppose, the whole business of line ending
                    conventions is messy.
                    It seems a strange for PHP to place an extra limitation like this on line
                    lengths. It's not really a problem as line wrapping at 70 chars looks
                    perfectly neat in all email clients I've ever used. As it happens between
                    70 and 75 chars are the settings I've always used when manually setting
                    word wrap in my email client's options.

                    My question was why PHP places this restriction at all. It's not even
                    sending the mail itself anyway, just passing the email to 'sendmail',
                    surely then it should simply be concerned with whatever line length
                    restrictions 'sendmail' imposes.

                    I've just looked in the sendmail manual which says it conforms to RFC 821,
                    this is the SMTP standard, URL - http://www.ietf.org/rfc/rfc0821.txt

                    The relevant bit of the RFC 821 SMTP standard says:

                    "Text Line - The maximum total length of a text line including the <CRLF>
                    is 1000 characters (but not counting the leading dot duplicated for
                    transparency)."

                    AFAICT SMTP does not place any further restrictions on message body line
                    lengths (though other fields do have text length restrictions such as the
                    reply line being a max. of 512 chars). I can't find any reference in the
                    protocol to message body lines (or any other lines) being further limited
                    to either 70 or 78 characters.

                    With that said, why is PHP concerned with further limits? Why not just let
                    the user enter their own newlines, the programmer add a CRLF at 998 chars
                    if necessary, and let the recipient's email client handle line wrapping as
                    per it's own settings/user options?

                    Any comments?

                    Regards, etc..

                    Matthew

                    Comment

                    Working...