Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multipart Email -- Both HTML and Plain Text 1

Status
Not open for further replies.

Glowball

Programmer
Oct 6, 2001
373
US
Hey all, I've been researching for awhile and can't figure out how to send an email that contains both the HTML and plain text versions in one email (allowing the client software to pick and choose). How do I use the separators (like with MIME encoding) to send text/plain and text/html?

Thanks!
 
More info... I need to do something like this:

--MIME_BOUNDARY
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Plain text message goes here.

--MIME_BOUNDARY
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

Code:
<html>
<body>
HTML message goes here.
</body>
</html>
 
I used to do it by sending a plain text and attaching an html version... it worked well. Try using the mime_mail class for it... -gerrygerry

Standard response to one of my posts:
&quot;No where in your entire rantings did you come anywhere close to what can be considered a rational answer. We are all now dumber from having heard that. I award you no points and may God have mercy on your soul.&quot;
 
Really? So what happens when the client is HTML-enabled? Do they see plain text with an attachment or do they see the attachment and no plain text? Interesting...
 
In my experience, it usually displayed the html with no plain text... i didn't test it very extensivly though. i have limited resources (namely, Outlook 2000 and various webmail interfaces), but it seemed to work fine in those... i think i had to name the html file something special though... i will take a look through my archives and see if I can find it...

[neutral]gerrygerry walks to entire wall of filing cabinets [reading][yawn][sleeping2]

this might take a while... -gerrygerry

Standard response to one of my posts:
&quot;No where in your entire rantings did you come anywhere close to what can be considered a rational answer. We are all now dumber from having heard that. I award you no points and may God have mercy on your soul.&quot;
 
Thanks all, I'll poke at this some more tomorrow. I'm still convinced I can pass it MIME and Content-Type info in the mail() tag, then use boundaries to set the text/html and text/plain parts. I swear I'm close... driving me crazy.

*insane look*
 
lmao... im sure it can be done that way too... i just have no idea how ;-) -gerrygerry

Standard response to one of my posts:
&quot;No where in your entire rantings did you come anywhere close to what can be considered a rational answer. We are all now dumber from having heard that. I award you no points and may God have mercy on your soul.&quot;
 
Sure you can,

You just need to pass it the correct headers, which I think should be multipart/alternative for the main type e.g.


...
...
Content-Type: multipart/alternative;
boundary=&quot;--thisisaboundary--&quot;
...
...
...
----thisisaboundary--
Content-Type: text/plain;
charset=&quot;ISO-8859-1&quot;
...
...
----thisisaboundary--
Content-Type: text/html;
charset=&quot;ISO-8859-1&quot;
...
...

I actually thought that first link had more info about MIME than it does sorry, but do a search for MIME stuff and have a bit of a read.

Hope this helps. [smurf]
01101000011000010110010001110011
 
Anyone have any thoughts about the following?

Code:
$plain_text = &quot;This is a plain text email.\r\nIt is very cool.&quot;;
$html_text = &quot;<html><body bgcolor=silver>This is a plain text email.<br>It is very cool.</body></html>&quot;;

$semi_rand = md5(time());
$mime_boundary = &quot;==MULTIPART_BOUNDARY_$semi_rand&quot;;
$boundary_header = chr(34) . $mime_boundary . chr(34);

$body = &quot;This is a multi-part message in MIME format.

--$mime_boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is the text portion of the mixed message.

--$mime_boundary
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<html><body><p>This is the <b>HTML portion</b> of the mixed message.</p></body></html>

--$mime_boundary--&quot;;

mail(&quot;me@me.com&quot;, &quot;Test Email&quot;, $body, 
    &quot;From: you@you.com\n&quot; . 
    &quot;MIME-Version: 1.0\n&quot; . 
    &quot;Content-Type: multipart/alternative;\n&quot; . 
    '     boundary=$boundary_header');
 
Found it! You can help yourselves to the solution in the PHP FAQs at faq434-2681 -- it was just a matter of trial and error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top