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

Forming a plain/html multipart e-mail message, probs with plaintext part

P: n/a
LRW
Because I've had recipients of our newsletter tell us they can't (or
won't) receive HTML e-mail, I found out how to make an e-mail that
sends both HTML and a plaintext version in a multipart message.

Problem is, while the HTML version shows up fine in HTML enabled
clients like Outlook, in plaintext clients it either shows nothing in
the body or just an attachment link to the message source code.

I've tried different encodings and bits for the plaintext part, but
nothing changes. Am I doing something wrong?

Here's the code...
THANKS!!

$to="Recipient Name <the email goes here>";
$from="Sender Name <the email goes here>";
$subject="My first HTML E-mail";
$mime_boundary="==Multipart_Boundary_x".md5(mt_ran d())."x";
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type:multipart/alternative;\n" .
" boundary=\"{$mime_boundary}\r\n\"";
$headers.= "From: $from\r\n";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"us-ascii\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
"Printing Automation Wholesale Account E-Boot Camp
Welcome to the first session of E-Boot Camp!

--SNIP--
" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 8bit\n\n" .
"<html>

<head>
<title>Welcome to E-Boot Camp Phase I</title>
--SNIP--

</html>

";
if (mail($to, $subject, $message, $headers))
echo "Message Sent!";
else
echo "Failed to send message.";
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
LRW (de**@celticbear.com) wrote:
: Because I've had recipients of our newsletter tell us they can't (or
: won't) receive HTML e-mail, I found out how to make an e-mail that
: sends both HTML and a plaintext version in a multipart message.

: Problem is, while the HTML version shows up fine in HTML enabled
: clients like Outlook, in plaintext clients it either shows nothing in
: the body or just an attachment link to the message source code.

: I've tried different encodings and bits for the plaintext part, but
: nothing changes. Am I doing something wrong?

: Here's the code...
: THANKS!!

: $to="Recipient Name <the email goes here>";
: $from="Sender Name <the email goes here>";
: $subject="My first HTML E-mail";
: $mime_boundary="==Multipart_Boundary_x".md5(mt_ran d())."x";
: $headers = "From: $from\r\n" .
: "MIME-Version: 1.0\r\n" .
: "Content-Type:multipart/alternative;\n" .
: " boundary=\"{$mime_boundary}\r\n\"";
: $headers.= "From: $from\r\n";
: $message = "This is a multi-part message in MIME format.\n\n" .
: "--{$mime_boundary}\n" .
: "Content-Type: text/plain; charset=\"us-ascii\"\n" .
: "Content-Transfer-Encoding: 7bit\n\n" .
: "Printing Automation Wholesale Account E-Boot Camp
: Welcome to the first session of E-Boot Camp!
:
: --SNIP--
: " .
: "--{$mime_boundary}\n" .
: "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
: "Content-Transfer-Encoding: 8bit\n\n" .
: "<html>

: <head>
: <title>Welcome to E-Boot Camp Phase I</title>
: --SNIP--

: </html>

I don't see the ending boundary, "--{$mime_boundary}--", that might make a
difference.

However, I would have to see the raw text of the message that is received
to know for sure whether the message is correct or not.

Jul 17 '05 #2

P: n/a
Hello,

On 07/01/2004 05:44 PM, LRW wrote:
Because I've had recipients of our newsletter tell us they can't (or
won't) receive HTML e-mail, I found out how to make an e-mail that
sends both HTML and a plaintext version in a multipart message.

Problem is, while the HTML version shows up fine in HTML enabled
clients like Outlook, in plaintext clients it either shows nothing in
the body or just an attachment link to the message source code.

I've tried different encodings and bits for the plaintext part, but
nothing changes. Am I doing something wrong?


It is hard to tell at the first glance. You may want to try this popular
class that does it right.

http://www.phpclasses.org/mimemessage
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #3

P: n/a
On Thu, 01 Jul 2004 20:57:40 -0300, Manuel Lemos <ml****@acm.org>
calmly ranted:
Hello,

On 07/01/2004 05:44 PM, LRW wrote:
Because I've had recipients of our newsletter tell us they can't (or
won't) receive HTML e-mail, I found out how to make an e-mail that
sends both HTML and a plaintext version in a multipart message.

Problem is, while the HTML version shows up fine in HTML enabled
clients like Outlook, in plaintext clients it either shows nothing in
the body or just an attachment link to the message source code.

I've tried different encodings and bits for the plaintext part, but
nothing changes. Am I doing something wrong?


It is hard to tell at the first glance. You may want to try this popular
class that does it right.

http://www.phpclasses.org/mimemessage


You provide a _very_ comprehensive class there, Manuel.
Do you by any chance have an instruction manual for it?
;)
--
If you turn the United States on its side,
everything loose will fall to California.
--Frank Lloyd Wright

Jul 17 '05 #4

P: n/a
Hello,

On 07/02/2004 02:21 PM, Larry Jaques wrote:
Because I've had recipients of our newsletter tell us they can't (or
won't) receive HTML e-mail, I found out how to make an e-mail that
sends both HTML and a plaintext version in a multipart message.

Problem is, while the HTML version shows up fine in HTML enabled
clients like Outlook, in plaintext clients it either shows nothing in
the body or just an attachment link to the message source code.

I've tried different encodings and bits for the plaintext part, but
nothing changes. Am I doing something wrong?


It is hard to tell at the first glance. You may want to try this popular
class that does it right.

http://www.phpclasses.org/mimemessage

You provide a _very_ comprehensive class there, Manuel.
Do you by any chance have an instruction manual for it?
;)


Not yet. I can produce a reference manual soon from the class
auto-documentation. It would for instance like in this class:

http://www.phpclasses.org/xmlwriter

It will take me a few days. Just let me know if that would be useful.

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #5

P: n/a
On Fri, 02 Jul 2004 18:43:15 -0300, Manuel Lemos <ml****@acm.org>
calmly ranted:
Hello,

On 07/02/2004 02:21 PM, Larry Jaques wrote:
Because I've had recipients of our newsletter tell us they can't (or
won't) receive HTML e-mail, I found out how to make an e-mail that
sends both HTML and a plaintext version in a multipart message.

Problem is, while the HTML version shows up fine in HTML enabled
clients like Outlook, in plaintext clients it either shows nothing in
the body or just an attachment link to the message source code.

I've tried different encodings and bits for the plaintext part, but
nothing changes. Am I doing something wrong?

It is hard to tell at the first glance. You may want to try this popular
class that does it right.

http://www.phpclasses.org/mimemessage

You provide a _very_ comprehensive class there, Manuel.
Do you by any chance have an instruction manual for it?
;)


Not yet. I can produce a reference manual soon from the class
auto-documentation. It would for instance like in this class:

http://www.phpclasses.org/xmlwriter

It will take me a few days. Just let me know if that would be useful.


Yes, please, VERY. I told my client I'd have her HTML newsletter up
and ready to be sent out by last Thursday (Yesterday). In the
interim, I'm trying to get the simpler (200 lines vs. your 1,200)
code from Kartic Krishnamurthy to work.
http://www.phpbuilder.com/columns/kartic20000807.php3

She (client) sent the Front Page-generated (ugh!) HTML email and
it's making the program barf with parse errors. After trimming
90% of the content, it then started giving me missing file warnings,
so I found where they went. It's now working without most of the
content, so I'm adding bits and pieces, trying it as I go. I get
no feedback with the current setup. Maybe I should add that before
I continue...

Arrrrrrrrrrrgh! In working with her old newsletter, the string
"Valentine's Day" was the culprit. Three stray catastrophes
(apostrophes) got me.

--
"Not always right, but never uncertain." --Heinlein
-=-=-
http://www.diversify.com Wondrous Website Design

Jul 17 '05 #6

P: n/a
Hello,

On 07/03/2004 02:29 AM, Larry Jaques wrote:
>I've tried different encodings and bits for the plaintext part, but
>nothing changes. Am I doing something wrong?

It is hard to tell at the first glance. You may want to try this popular
class that does it right.

http://www.phpclasses.org/mimemessage
You provide a _very_ comprehensive class there, Manuel.
Do you by any chance have an instruction manual for it?
;)
Not yet. I can produce a reference manual soon from the class
auto-documentation. It would for instance like in this class:

http://www.phpclasses.org/xmlwriter

It will take me a few days. Just let me know if that would be useful.

Yes, please, VERY. I told my client I'd have her HTML newsletter up


It is almost done and I will probably release it later today, but if you
are in a hurry, you should look at the example scripts supplied with the
class.

and ready to be sent out by last Thursday (Yesterday). In the
interim, I'm trying to get the simpler (200 lines vs. your 1,200)
code from Kartic Krishnamurthy to work.
http://www.phpbuilder.com/columns/kartic20000807.php3

She (client) sent the Front Page-generated (ugh!) HTML email and
it's making the program barf with parse errors. After trimming
90% of the content, it then started giving me missing file warnings,
so I found where they went. It's now working without most of the
content, so I'm adding bits and pieces, trying it as I go. I get
no feedback with the current setup. Maybe I should add that before
I continue...
HTML messages should be composed properly according to the standards
from RFC to prevent having your messages be discarded by spam filters.
If you are not sure what you are doing, I would not recommend hacking
somebody else's code because it is easy to make it generate improperly
formatted messages.

Arrrrrrrrrrrgh! In working with her old newsletter, the string
"Valentine's Day" was the culprit. Three stray catastrophes
(apostrophes) got me.


It sound like you have magic quotes enabled. You should disable them in
that case.
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.