Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 17th, 2003, 08:22 PM
Registered User
 
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default E-mail HTML Form

Good Evening,
I am trying to send a completed form in an HTML format. I would like to have the user open their e-mail and have the form pop up with the fields populated with the data I input. I have added the HTML tags and they show up as part of the text. I got the e-mail part down, it is just the format I am not able to work out.
If someone has done this before please enlighten me.

Thanks

 
Old December 17th, 2003, 08:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's because you need to set the content type of the email to HTML. There are several utility classes written in PHP to simplify the process of creating HTML emails, sending attachments, etc.

For example:
  http://www.phpguru.org/mime.mail.html

Using utility classes like this make things a lot easier, as all you need to do is include the class definition file, create the mail object, set the mime type to HTML, and send your message.

There's one available with PEAR (http://pear.php.net/) and another at http://www.phpguru.org/.

Rich (quesadilla5) probably knows which ones are the best.

If you prefer to do it by yourself, you can follow the example given in the manual:
  http://www.php.net/function.mail


Take care,

Nik
http://www.bigaction.org/
 
Old December 17th, 2003, 09:31 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Yeah Richard Heyes' MIME class is designed to do that sort of thing. The class allows one to form multipart messages, html part, text alternative, html with embedded images, and allows for file attachments.

If you download the class you should see several examples there with the downloaded files that will show you how to use it.

The PEAR class is simply Heyes' original class from phpguru.org ported to the standardized PEAR format... so both versions are probably the same. You'll probably get better doumentation downloading the class from phpguru.org than from PEAR. I didn't see all the examples in the PEAR version as I did in the download from his site. All in all it isn't actually too daunting to use if you look through all the examples.

The simpilest method without fooling with the MIME class is to add the content-type as a header in the 4th argument of the mail function, like Nik mentioned, which is done like this: (I threw in a few extra headers)

$headers = "From: Display Name Here <[email protected]>\r\nReply-to: [email protected]\r\nContent-type: text/html; charset=us-ascii";

The content-type header is what will trigger *most* email programs to display the message as rendered HTML.

mail("[email protected]", "Subject", "Body", $headers);

So yeah basically the same as what you would have read in the PHP manual.

However, this method does not allow the luxury of attaching a plain text alternative to the message as Heyes' class does... well that is not without a more complex script.

hth,
: )
Rich


:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old December 17th, 2003, 09:46 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Oh I made a goof:

$headers = "From: Display Name Here <[email protected]>\r\nReply-to: [email protected]\r\nContent-type: text/html; charset=us-ascii\r\n";

You should include a carriage return and newline at the end of every header entry including the last.


:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old December 18th, 2003, 12:32 PM
Registered User
 
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the help and resource. I will give this one a go.








Similar Threads
Thread Thread Starter Forum Replies Last Post
how to extract contents of an e-mail in html/rtf mogli PHP How-To 5 September 15th, 2004 04:25 PM
HTML formatted mail goes to BadMail. Why? nancy Classic ASP Basics 12 August 24th, 2004 10:19 AM
Sending a CSS formatted HTML mail madhukp Classic ASP Basics 4 June 17th, 2004 11:30 PM
Sending both text mail and HTML mail - CDONTS madhukp Classic ASP Basics 1 October 8th, 2003 01:05 AM
HTML Mail Problem [email protected] HTML Code Clinic 0 September 28th, 2003 10:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.