Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To 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 March 18th, 2009, 09:42 AM
Registered User
 
Join Date: Mar 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Receiving data from form in html format email

I'm using a form on my web site to send information to me via and e-mail. Everything works fine. However I would like the info to arrive within an HTML table in the e-mail so as to set it up in columns . Is it possible to do this and if so can you point me to a source for this information. Thank-you for your help. T
 
Old March 18th, 2009, 03:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default some thoughts

Can you provide more detail on how the form is sent to you, for example are you using the following approach :

Code:
<form action="mailto:admin@example.com" enctype="text/plain" method="post">
or is the data being sent via a POST / GET method to a PHP script for processing ?

If it is the latter then you should be able to use something like http://uk2.php.net/manual/en/function.mail.php which has an example of sending mail in a HTML format.
__________________
All the best

Greg
------------------
Greg Griffiths
Web & Livelink Developer
http://www.greggriffiths.org
 
Old March 19th, 2009, 07:21 AM
Registered User
 
Join Date: Mar 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

Hi Greg, Thank-you for responding.

The data is being sent by POST to a PHP script for processing.
It's the usual Name, address, email etc. I did look at http://uk2.php.net/manual/en/function.mail.php and saw

$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
etc.

That's just what I want but how do I get the data from the form into the <td> </td>s

$message .= 'Name: '.$_POST['name']."\n\n";
$message .= 'Address: '.$_POST['address1']."\n\n";
$message .= 'Address: '.$_POST['address2']."\n\n";
$message .= 'City: '.$_POST['city']."\n\n";
etc.

Thank-you again for your time. Talbot
 
Old March 23rd, 2009, 12:13 AM
Authorized User
 
Join Date: Feb 2009
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Default

While Generating the $message Variable (from your example code)
you can concatenate your POSTed values into the string. SO that we can receive it as you deserved

for eg:

$message = '<table>
<tr>
<td colspan=2>Contact Information</td>
</tr>
<tr>
<td>Name:</td>
<td>'.$_POST['name'].'</td>
</tr>
<tr>
<td>Address1:</td>
<td>'.$_POST['address1'].'</td>
</tr>
<tr>
<td>Address2:</td>
<td>'.$_POST['address2'].'</td>
</tr>
</table>'


Regards
Anees
 
Old March 23rd, 2009, 05:05 PM
Registered User
 
Join Date: Mar 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Anees,
Thank-you for your reply.
I did as you suggested and when I received the e-mail the data from the variable was there. However all the html code was there as well, see below:
Code:
<table>
<tr>
<td colspan=2>Contact Information</td>
</tr>
<tr>
<td>Name:</td>
<td>Peter Rawlins</td>
</tr>
<tr>
<td>Address:</td>
<td>205 Somerset</td>
</tr>
<tr>
<td>City:</td>
<td>Oshawa</td>
</tr>
etc.

Is there anyway around this now? Thank-agin for your help. T
 
Old March 23rd, 2009, 11:44 PM
Authorized User
 
Join Date: Feb 2009
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Default

It is just because you sent the e mail as text(default)
To receive HTML emails you need to set header Content-type as HTML
and also the MIME-Version

PHP Code:
<?php 
mail
('recipient@some.net''Subject'
     
'<html><body><p>Your <i>message</i> here.</p></body></html>'
     
"To: The Receiver <recipient@some.net>\n" 
     
"From: The Sender <sender@some.net>\n" 
     
"MIME-Version: 1.0\n" 
     
"Content-type: text/html; charset=iso-8859-1"); 
?>
Regards
Anees
 
Old March 24th, 2009, 10:54 AM
Registered User
 
Join Date: Mar 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank-you very much Anees, it works perfectly now.
All the best. T





Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML email format in Lotus Notes. mcinar Classic ASP Professional 2 June 5th, 2007 09:33 AM
Email html format with image robprell Perl 3 May 9th, 2007 05:20 PM
Display field containing data in HTML format hui2602 Reporting Services 0 April 27th, 2006 04:35 AM
email in html format alitoday HTML Code Clinic 3 June 19th, 2004 08:31 AM
Build HTML email from form jmccann Classic ASP Basics 2 July 22nd, 2003 09:47 PM





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