Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 14th, 2005, 05:02 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default plain vs HTML format

Does somebody know a solution to that?

for a email application you are commonly required to send out emails in HTML format as well as in Plain text format. I figured how you can send different versions out dependent on a status which you retrieve out of a database. However, this requires that the recipient first has to specify whether he wants plain or HTML.

Is there a possibility to send out only the HTML version and the plain text recipients won't see any code, just plain text? so means that the code tags get stripped off, as well as the MIME headers.

So you wouldnt have to specify anymore what you want to receive. No matter if your email supports plain or HTML you only receive a version that shows the format applicable to your email provider.

Thanks for help

Reply With Quote
  #2 (permalink)  
Old April 17th, 2005, 04:30 AM
Authorized User
 
Join Date: Apr 2005
Location: Spring Hill, Florida, USA.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 Yes you can send a multi-part message with one part plain text and the other part containing your HTML. Clients that understand MIME, but not HTML will render the plain text version and ignore the HTML. Clients that understand HTML will render the HTML. Here is an example:

<?php
   $to="Recipient Name <somebody@example.com>";
   $from="Sender Name <jdoe@example.com>";
   $subject="Subject";
// HTML
   $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" .
// Plain Text Part
      "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
      "Content-Transfer-Encoding: 7bit\n\n" .
      "HTML E-mail\n\nThis is the text portion of an HTML e-mail\n" .
      "--{$mime_boundary}\n" .
      "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
      "Content-Transfer-Encoding: 7bit\n\n" .
      "<h1>HTML E-mail</h1>" .
      "<p>This is an <b>HTML</b> e-mail.</p>";
   if (mail($to, $subject, $message, $headers))
      echo "Message Sent!";
   else
      echo "Failed to send message.";
?>


     Take note that the content type is set to "multipart/alternative". Then we place boundary markers between the two versions of the message and set a content type for each part. What this means is that we're sending two versions of the message. The e-mail client can choose which of these to display. If the e-mail client understands HTML, it will display it. If it doesn't understand HTML, it will display the plain text version.

  Hope that does the trick.

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent
Reply With Quote
  #3 (permalink)  
Old April 19th, 2005, 08:42 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Cheers Bobby Fisher

seems like its working...thanks heaps for your help, saved me a lot of hours research on the internet

J

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent - Send mail with plain view and html view ashish.dadhwal ASP.NET 2.0 Professional 0 November 27th, 2008 01:49 AM
How to show plain format from html hdpark BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 14 November 26th, 2008 05:31 PM
email in html format alitoday HTML Code Clinic 3 June 19th, 2004 08:31 AM



All times are GMT -4. The time now is 03:52 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.