sending multiline mail in text format

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

    sending multiline mail in text format

    hi,
    Bonjour,

    I'm using PHPMailer class to send mails and it works fine for HTML ones.

    But I can't manage to send correctly a text formatted mail...
    I tried this :
    - $message = "first line*\n*second line";
    - $message = "first line*\r\n*secon d line";
    - $message = "first line*".chr(13). chr(10)*second line";
    - $message = "first line*
    *second line";

    Result is always the same (I tried many mail readers like Outlook express,
    Yahoo, ...) : the body appears on only one line, with a space between the 2
    *, instead of a carriage return...
    first line* *second line

    Thanks for any idea !


  • John Bokma

    #2
    Re: sending multiline mail in text format

    Christophe Cerbourg wrote:
    [color=blue]
    > hi,
    > Bonjour,
    >
    > I'm using PHPMailer class to send mails and it works fine for HTML
    > ones.
    >
    > But I can't manage to send correctly a text formatted mail...
    > I tried this :
    > - $message = "first line*\n*second line";
    > - $message = "first line*\r\n*secon d line";
    > - $message = "first line*".chr(13). chr(10)*second line";
    > - $message = "first line*
    > *second line";
    >
    > Result is always the same (I tried many mail readers like Outlook
    > express, Yahoo, ...) : the body appears on only one line, with a space
    > between the 2 *, instead of a carriage return...
    > first line* *second line
    >
    > Thanks for any idea ![/color]

    I guess the mail is sent as HTML anyway, and an end of line is just
    whitespace in HTML in most circumstances.

    Check the source of the email message to see if this is the case (Ctrl + F3
    ?)

    --
    John MexIT: http://johnbokma.com/mexit/
    personal page: http://johnbokma.com/
    Experienced programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html

    Comment

    • nc@iname.com

      #3
      Re: sending multiline mail in text format

      Christophe Cerbourg wrote:[color=blue]
      >
      > I'm using PHPMailer class to send mails and it works fine for HTML[/color]
      ones.[color=blue]
      >
      > But I can't manage to send correctly a text formatted mail...
      > I tried this :
      > - $message = "first line*\n*second line";
      > - $message = "first line*\r\n*secon d line";
      > - $message = "first line*".chr(13). chr(10)*second line";
      > - $message = "first line*
      > *second line";
      >
      > Result is always the same (I tried many mail readers like Outlook
      > express, Yahoo, ...) : the body appears on only one line, with
      > a space between the 2 *, instead of a carriage return...[/color]

      You probably call IsHTML(true) somewhere... This makes PHPMailer
      generate e-mail headers that suggest that the message body is
      HTML while it is in fact plain text. The recepient client
      attempts to render it as HTML, and so you have your line breaks
      missing in this incorrect rendition...

      Cheers,
      NC

      Comment

      • Ronald Chaplin

        #4
        Re: sending multiline mail in text format

        nc@iname.com wrote:[color=blue]
        > Christophe Cerbourg wrote:
        >[color=green]
        >>I'm using PHPMailer class to send mails and it works fine for HTML[/color]
        >
        > ones.
        >[color=green]
        >>But I can't manage to send correctly a text formatted mail...
        >>I tried this :
        >>- $message = "first line*\n*second line";
        >>- $message = "first line*\r\n*secon d line";
        >>- $message = "first line*".chr(13). chr(10)*second line";
        >>- $message = "first line*
        >>*second line";
        >>
        >>Result is always the same (I tried many mail readers like Outlook
        >>express, Yahoo, ...) : the body appears on only one line, with
        >>a space between the 2 *, instead of a carriage return...[/color]
        >
        >
        > You probably call IsHTML(true) somewhere... This makes PHPMailer
        > generate e-mail headers that suggest that the message body is
        > HTML while it is in fact plain text. The recepient client
        > attempts to render it as HTML, and so you have your line breaks
        > missing in this incorrect rendition...
        >
        > Cheers,
        > NC
        >[/color]
        To try and confirm this, you could look at the original message, as it
        is seen by the mail reader. i.e. unparsed. That should give you some
        clue as to what type of document it is being sent as.

        HTH


        --
        Ron Chaplin
        =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        T73 Software & Design

        To provide custom and quality
        software, designs and services,
        to our customers, at an affordable rate,
        with minimal delay.

        Comment

        • cc

          #5
          Re: sending multiline mail in text format

          [color=blue]
          > You probably call IsHTML(true) somewhere...[/color]

          here is the complete code used for testing :
          $message = "première ligne*\n*deuxiè me ligne";

          $monmail = new PHPMailer();
          $monmail->SetLanguage("f r", "");
          $monmail->IsHTML(False );

          // $monmail->Encoding = "base64";
          $monmail->From = "me@home.fr ";
          $monmail->FromName = "xxx";
          $monmail->ClearAddresses ();
          $monmail->ClearCCs();
          $monmail->ClearBCCs();
          $monmail->AddAddress("ad dress@voila.fr" );

          $monmail->Subject = "test";
          $monmail->Body = $message;
          $monmail->AltBody = $message;

          if ($monmail->Send()) { echo "ok 1"; } else { echo "erreur"; }

          and here is the result :
          première ligne* *deuxième ligne

          But, as you suggest, I will have a look to the whole content of message...
          Thanks anyway !


          Comment

          • cc

            #6
            Re: sending multiline mail in text format

            [color=blue]
            > To try and confirm this, you could look at the original message, as it
            > is seen by the mail reader. i.e. unparsed. That should give you some
            > clue as to what type of document it is being sent as.[/color]

            hi Ron, thanks for your help.

            Here is the complete message in which I don't understand anything...
            Is it correct for a TEXT mail or not ?

            Received: from serveur20.dns-oi.com ([213.11.110.6]) by
            decalogexc.papr ika.net with Microsoft SMTPSVC(5.0.219 5.6713);
            Tue, 11 Jan 2005 16:46:49 +0100
            Received: from serveur41 (212.208.222.4) by serveur20.dns-oi.com (NPlex
            5.1.036)
            id 41E3CAB90000179 5 for address@server. net; Tue, 11 Jan 2005
            16:39:41 +0100
            Received: from 212.208.222.4 by serveur41 (InterScan E-Mail VirusWall NT);
            Tue, 11 Jan 2005 16:39:41 +0100
            Received: from source ([212.208.222.4]) by host ([212.208.222.4]) with SMTP;
            Tue, 11 Jan 2005 16:39:41 +0100
            Received: from phpnet.org ([195.137.249.140])
            by serveur41.dns-oid.com (OID Mail Server v3.0) with SMTP id
            GLD38335
            for <address@server .net>; Tue, 11 Jan 2005 16:39:41 +0100
            Received: (qmail 27424 invoked by uid 502); 11 Jan 2005 15:39:52 -0000
            Received: from unknown (HELO cluster2.phpnet .org) (10.0.0.38)
            by 10.0.0.101 with SMTP; 11 Jan 2005 15:39:52 -0000
            Received: (qmail 23718 invoked by uid 510); 11 Jan 2005 15:39:35 -0000
            To: address@server. net
            Subject: test
            Date: Tue, 11 Jan 2005 16:39:35 +0100
            From: volleyloisirs <address@volley loisirs.server. org>
            Message-ID: <915ff4313334a0 4c16704ed017fe6 331@volleyloisi rs.server.org>
            X-Priority: 3
            X-Mailer: PHPMailer [version 1.72]
            MIME-Version: 1.0
            Content-Type: multipart/mixed;
            boundary="----=_NextPartTM-000-c8e1a65e-e615-4f65-9337-a3f0937796e1"
            X-pstn-version: pmps:sps_win32_ 1_1_0c1 pase:2.8
            X-pstn-levels: (C:78.1961 M:98.9607 P:95.9108 R:95.9108 S: 1.1377 )
            X-pstn-settings: 4 (0.2500:0.7500) p:14 m:14 C:14 r:14
            X-pstn-addresses: from <address@volley loisirs.server. org> forward (org good)
            Return-Path: address@volleyl oisirs.server.o rg
            X-OriginalArrival Time: 11 Jan 2005 15:46:49.0921 (UTC)
            FILETIME=[C39E0310:01C4F7 F4]


            ------=_NextPartTM-000-c8e1a65e-e615-4f65-9337-a3f0937796e1
            Content-Type: multipart/alternative;
            boundary="b1_91 5ff4313334a04c1 6704ed017fe6331 "

            --b1_915ff4313334 a04c16704ed017f e6331
            Content-Type: text/plain; charset = "iso-8859-1"
            Content-Transfer-Encoding: 8bit

            première ligne*
            *deuxième ligne


            --b1_915ff4313334 a04c16704ed017f e6331
            Content-Type: text/html; charset = "iso-8859-1"
            Content-Transfer-Encoding: 8bit

            première ligne*
            *deuxième ligne



            --b1_915ff4313334 a04c16704ed017f e6331--


            ------=_NextPartTM-000-c8e1a65e-e615-4f65-9337-a3f0937796e1--


            Comment

            • Alvaro G Vicario

              #7
              Re: sending multiline mail in text format

              *** cc wrote/escribió (Tue, 11 Jan 2005 16:45:44 +0100):[color=blue]
              > --b1_915ff4313334 a04c16704ed017f e6331
              > Content-Type: text/plain; charset = "iso-8859-1"
              > Content-Transfer-Encoding: 8bit
              >
              > première ligne*
              > *deuxième ligne
              >
              >
              > --b1_915ff4313334 a04c16704ed017f e6331
              > Content-Type: text/html; charset = "iso-8859-1"
              > Content-Transfer-Encoding: 8bit
              >
              > première ligne*
              > *deuxième ligne[/color]

              You are sending two copies of the body message: a text plain and an HTML
              version. Your mail client probably displays the HTML version which, as you
              can see, has not markup tags at all.


              --
              -- Álvaro G. Vicario - Burgos, Spain
              -- Thank you for not e-mailing me your questions
              --

              Comment

              • Alvaro G Vicario

                #8
                Re: sending multiline mail in text format

                *** cc wrote/escribió (Tue, 11 Jan 2005 14:20:42 +0100):[color=blue]
                > $monmail->Body = $message;
                > $monmail->AltBody = $message;[/color]



                string $AltBody = "" (line 96)

                Sets the text-only body of the message. This automatically sets the email
                to multipart/alternative. This body can be read by mail clients that do not
                have HTML email capability such as mutt. Clients that can read HTML will
                view the normal Body.

                Duplicating the body makes no sense it you aren't sending formatted text.


                --
                -- Álvaro G. Vicario - Burgos, Spain
                -- Thank you for not e-mailing me your questions
                --

                Comment

                • cc

                  #9
                  Re: sending multiline mail in text format

                  thanks Alvaro for your help.

                  I had understood, while reading this help, that I could avoid writing a HTML
                  message if I wanted it to be always displayed in text. But it seems I always
                  have to write it in HTML because if I only set the AltBody property, the
                  mail is empty with OE, for example...

                  So I have to set two versions of my poor text message, one with <br> in the
                  body, and one with \n in the AltBody ?

                  It works fine if I do that, but it makes me feel programming is really a
                  stupid job, sometimes...

                  Anyway, thanks !


                  Comment

                  • Alvaro G Vicario

                    #10
                    Re: sending multiline mail in text format

                    *** cc wrote/escribió (Tue, 11 Jan 2005 17:43:04 +0100):[color=blue]
                    > I had understood, while reading this help, that I could avoid writing a HTML
                    > message if I wanted it to be always displayed in text. But it seems I always
                    > have to write it in HTML because if I only set the AltBody property, the
                    > mail is empty with OE, for example...[/color]

                    You don't have to set the AltBody property for plain text. Alternative to
                    what?? Just leave it apart.


                    --
                    -- Álvaro G. Vicario - Burgos, Spain
                    -- Thank you for not e-mailing me your questions
                    --

                    Comment

                    • nc@iname.com

                      #11
                      Re: sending multiline mail in text format

                      cc wrote:[color=blue]
                      >[color=green]
                      > > You probably call IsHTML(true) somewhere...[/color]
                      >
                      > here is the complete code used for testing :[/color]

                      And here is the line that is responsible for your problems:
                      [color=blue]
                      > $monmail->AltBody = $message;[/color]

                      You don't need AltBody for a plain-text message. You should
                      delete this line.

                      Cheers,
                      NC

                      Comment

                      • cc

                        #12
                        Re: sending multiline mail in text format

                        [color=blue]
                        > You don't have to set the AltBody property for plain text. Alternative to
                        > what?? Just leave it apart.[/color]

                        yes I have to...
                        if I send "first line*<br>*secon d line" with $MyMail->IsHTML(False ), most of
                        mail readers display
                        first line*
                        *second line
                        but not all of them !
                        Some display :
                        first line*<br>*secon d line

                        If I send <br> in Body and \n in AltBody, mail is correctly displayed in ALL
                        mail readers I tested.

                        Thanks !


                        Comment

                        • cc

                          #13
                          Re: sending multiline mail in text format

                          > You don't need AltBody for a plain-text message. You should[color=blue]
                          > delete this line.[/color]

                          thanks for your help
                          see my answer to Alvaro please...


                          Comment

                          • Alvaro G Vicario

                            #14
                            Re: sending multiline mail in text format

                            *** cc wrote/escribió (Wed, 12 Jan 2005 09:23:39 +0100):[color=blue]
                            > yes I have to...
                            > if I send "first line*<br>*secon d line" with $MyMail->IsHTML(False ), most of
                            > mail readers display
                            > first line*
                            > *second line
                            > but not all of them !
                            > Some display :
                            > first line*<br>*secon d line[/color]

                            Which is the correct behaviour. Your original post is titled "sending
                            multiline mail in text format". Why do you want to put HTML tags in a plain
                            text message and get them parsed?


                            --
                            -- Álvaro G. Vicario - Burgos, Spain
                            -- Thank you for not e-mailing me your questions
                            --

                            Comment

                            • cc

                              #15
                              Re: sending multiline mail in text format

                              > Which is the correct behaviour. Your original post is titled "sending[color=blue]
                              > multiline mail in text format". Why do you want to put HTML tags in a[/color]
                              plain[color=blue]
                              > text message and get them parsed?[/color]

                              Well... What I wanted to to was just send a very simple text message, in
                              text format.

                              But I also want the very simple message to have 2 lines !

                              So I first send message like this :
                              $message = "première ligne*\n*deuxiè me ligne";

                              $monmail = new PHPMailer();
                              $monmail->SetLanguage("f r", "");
                              $monmail->IsHTML(False );
                              ....
                              $monmail->Subject = "test";
                              $monmail->Body = $message;

                              if ($monmail->Send()) { echo "ok 1"; } else { echo "erreur"; }

                              As result was not what I guessed ("première ligne* *deuxième ligne" instead
                              of
                              première ligne*
                              *deuxième ligne)

                              I tried many more other things and finally ask in this newsgroup.

                              Now I have a solution, thanks for this, but am surprised not to have a
                              simple solution for such a simple need...
                              If I want my 2 lines messages be seen as this by every news reader, I have
                              to set both Body and AltBody properties, one with "<br>" and the other with
                              "\n", which is not very complicated, but not as simple as I hoped !


                              Comment

                              Working...