By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,367 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

sending multiline mail in text format

P: n/a
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*second 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 !
Jul 17 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Christophe Cerbourg wrote:
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*second 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 !


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
Jul 17 '05 #2

P: n/a
nc
Christophe Cerbourg wrote:

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*second 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...


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

Jul 17 '05 #3

P: n/a
nc@iname.com wrote:
Christophe Cerbourg wrote:
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*second 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...

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

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
www.t73-softdesign.com
To provide custom and quality
software, designs and services,
to our customers, at an affordable rate,
with minimal delay.
Jul 17 '05 #4

P: n/a
cc
You probably call IsHTML(true) somewhere...


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

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

// $monmail->Encoding = "base64";
$monmail->From = "me@home.fr";
$monmail->FromName = "xxx";
$monmail->ClearAddresses();
$monmail->ClearCCs();
$monmail->ClearBCCs();
$monmail->AddAddress("ad*****@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 !
Jul 17 '05 #5

P: n/a
cc
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.


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.paprika.net with Microsoft SMTPSVC(5.0.2195.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 41E3CAB900001795 for ad*****@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 <ad*****@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: ad*****@server.net
Subject: test
Date: Tue, 11 Jan 2005 16:39:35 +0100
From: volleyloisirs <ad*****@volleyloisirs.server.org>
Message-ID: <91******************************@volleyloisirs.se rver.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 <ad*****@volleyloisirs.server.org> forward (org good)
Return-Path: ad*****@volleyloisirs.server.org
X-OriginalArrivalTime: 11 Jan 2005 15:46:49.0921 (UTC)
FILETIME=[C39E0310:01C4F7F4]
------=_NextPartTM-000-c8e1a65e-e615-4f65-9337-a3f0937796e1
Content-Type: multipart/alternative;
boundary="b1_915ff4313334a04c16704ed017fe6331"

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

première ligne*
*deuxième ligne
--b1_915ff4313334a04c16704ed017fe6331
Content-Type: text/html; charset = "iso-8859-1"
Content-Transfer-Encoding: 8bit

première ligne*
*deuxième ligne

--b1_915ff4313334a04c16704ed017fe6331--
------=_NextPartTM-000-c8e1a65e-e615-4f65-9337-a3f0937796e1--
Jul 17 '05 #6

P: n/a
*** cc wrote/escribió (Tue, 11 Jan 2005 16:45:44 +0100):
--b1_915ff4313334a04c16704ed017fe6331
Content-Type: text/plain; charset = "iso-8859-1"
Content-Transfer-Encoding: 8bit

première ligne*
*deuxième ligne
--b1_915ff4313334a04c16704ed017fe6331
Content-Type: text/html; charset = "iso-8859-1"
Content-Transfer-Encoding: 8bit

première ligne*
*deuxième ligne


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
--
Jul 17 '05 #7

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


http://phpmailer.sourceforge.net/docs/

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
--
Jul 17 '05 #8

P: n/a
cc
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 !
Jul 17 '05 #9

P: n/a
*** cc wrote/escribió (Tue, 11 Jan 2005 17:43:04 +0100):
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...


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
--
Jul 17 '05 #10

P: n/a
nc
cc wrote:
You probably call IsHTML(true) somewhere...
here is the complete code used for testing :


And here is the line that is responsible for your problems:
$monmail->AltBody = $message;


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

Cheers,
NC

Jul 17 '05 #11

P: n/a
cc
You don't have to set the AltBody property for plain text. Alternative to
what?? Just leave it apart.


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

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

Thanks !
Jul 17 '05 #12

P: n/a
cc
> You don't need AltBody for a plain-text message. You should
delete this line.


thanks for your help
see my answer to Alvaro please...
Jul 17 '05 #13

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


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
--
Jul 17 '05 #14

P: n/a
cc
> 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?


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("fr", "");
$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 !
Jul 17 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.