Jump to content

Recommended Posts

Ok this has been a little trickier then I had expected, currently I have a form that when submitted it just sends a regular email in plain text with all the information.  However I would like to be able to format the email so it is more organized with a table that contains the submitted information.  However all the tutorials I have gone over does not show how to pull information from the form fields and put them in the html message itself.  They just show how to send an email in html format without any form data.  My current code below is what I have been experimenting with and just sends plain text.  Can anyone give me some assistance as to how to have the form data submit in html?

 

<?

$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$phone = $_POST["phone"];
$GeneralAcuteCare = $_POST["GeneralAcuteCare"];
$HomeHealth = $_POST["HomeHealth"];
$SkilledNursingFacility = $_POST["SkilledNursingFacility"];
$OutpatientClinic = $_POST["OutpatientClinic"];
$comments = $_POST["comments"];

$to = "steve@domain.com";
$from = "test@domain.com";
$subject = "Skills Checklist";
$message  ="Name: $firstname  \n";
$message .="Phone: $phone \n\n";
$message .="General Acute Care: $GeneralAcuteCare \n";
$message .="Home Health: $HomeHealth \n";
$message .="Skilled Nursing Facility: $SkilledNursingFacility \n";
$message .="Out patient Clinic: $OutpatientClinic \n\n";
$message .="Comments: $comments \n";
if($comments != "")
{
   //send mail - $subject & $contents come from surfer input
   mail($to, $from, $subject, $message);
   // redirect back to url visitor came from
   header("Location: http://www.website.com/success.php");
}
  else
{
   print(" error ");
}
   
   ?>

 

I have tried adding the content type and mime version to the headers.  As per some examples I tried to insert the $firstname into the html code for the message and it does not pull the data.  I then tried to echo the data and that did not work either. 

Here is the form page, generic for now so I can try and figure this out.  I fill out the form and hit submit.  It then uses the code I listed above to generate and send out the email.  It works, but the email is in plain text.  I wish to have it send an email in html so I can format it with a table and 2 colums for the data to line up and look nicer. 

 

Generic form at the moment

[code]
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  <title></title>
  <meta name="description" content="">
</head>
<body>
	  

<form method="post" action="send.php">

<table border=0 summary="">

<tr>
<td width="300">First Name:</td>
<td><input type="text" name="firstname" size="25" maxlength="40">
</td>
</tr>

<tr>
<td width="300">Last Name:</td>
<td><input type="text" name="lasttname" size="25" maxlength="40">
</td>
</tr>

<tr>
<td width="300">Phone:</td>
<td><input type="text" name="phone" size="15" maxlength="15">
</td>
</tr>
</table>
<br><br>
<table border=0 summary="">
<tr>
	<td><b>Work Settings</b></td>
	<td> </td>
</tr>
<tr>
	<td width="300">General Acute Care</td>
	<td><select name="GeneralAcuteCare">
<option value=""></option>		
<option value="Theory, no practice"> Theory, no practice</option>
<option value="Intermittent experience"> Intermittent experience</option>
<option value="Experienced"> Experienced</option>
<option value="Supervise and Teach"> Supervise and Teach</option>
</select>
</td>
</tr>
<tr>
	<td width="300">Home Health</td>
			<td><select name="HomeHealth">
<option value=""></option>		
<option value="Theory, no practice"> Theory, no practice</option>
<option value="Intermittent experience"> Intermittent experience</option>
<option value="Experienced"> Experienced</option>
<option value="Supervise and Teach"> Supervise and Teach</option>
</select>
</td>
</tr>
<tr>
	<td width="300">Skilled Nursing Facility</td>
			<td><select name="SkilledNursingFacility">
<option value=""></option>		
<option value="Theory, no practice"> Theory, no practice</option>
<option value="Intermittent experience"> Intermittent experience</option>
<option value="Experienced"> Experienced</option>
<option value="Supervise and Teach"> Supervise and Teach</option>
</select>
</td>
</tr>
<tr>
	<td width="300">Out patient Clinic</td>
			<td><select name="OutpatientClinic">
<option value=""></option>		
<option value="Theory, no practice"> Theory, no practice</option>
<option value="Intermittent experience"> Intermittent experience</option>
<option value="Experienced"> Experienced</option>
<option value="Supervise and Teach"> Supervise and Teach</option>
</select>
</td>
</tr>
</table>

<table>
<tr>
<td><b>Comments:</b></td>
</tr>

<tr>
<td><textarea name="comments" cols="80" rows="10">
</textarea>
</td>
</tr>
</table>

<div align="right">
<input type="submit" value="Submit">
</div>
</form>
</body>
</html>

[/code]

Here is an html email I did a while ago:

 

$headers = "From: email@email.com\r\n";
$headers .= "Content-type: text/html\r\n";

$message = <<<EOF
<html>
  <body>
    <center>
<BR>
<table cellpadding="0" cellspacing="0" border="0" style="font-family:verdana;font-size:12px;padding:0px;border:1px black solid;">
<tr><td style="padding:5px;">
Whatever you want to say.
</td></tr></table>
</center>
  </body>
</html>
EOF;


mail("to@email.com", "Subject","$message",$headers);

 

Hope that helps you.

ok the form submits right? but you get it as plain text?

 

ok

 

I believe in order to send it as a HTML format you'll need to store it on the server so in a database then have the page sent and request the data from the database depending on the email address. I think it would be kinda complicating so if you don't have much experience with php you should stick with a text file

Yes Frost that will send in html, however you do not have any variables to assign in the email from a form.  I know how to store data into a mysql database and display results, however I was hoping to not have to create a database just for this form because there will be 5 other forms just asking different questions so the database will be quite large.

Ok, how about:

 

<?
@import_request_variables("p");
$headers = "From: email@email.com\r\n";
$headers .= "Content-type: text/html\r\n";

$message = <<<EOF
<html>
  <body>
    <center>
<BR>
<table cellpadding="0" cellspacing="0" border="0" style="font-family:verdana;font-size:12px;padding:0px;border:1px black solid;">
<tr><td style="padding:5px;">

Name: $firstname  
Phone: $phone <BR>
General Acute Care: $GeneralAcuteCare <BR>
Home Health: $HomeHealth <BR>
Skilled Nursing Facility: $SkilledNursingFacility <BR>
Out patient Clinic: $OutpatientClinic <BR>
Comments: $comments <BR>

</td></tr></table>
</center>
  </body>
</html>
EOF;


mail("to@email.com", "Subject","$message",$headers);

 

 

 

I see what my problem is, what I have been trying is very close to what you posted Frost and it does work.  However it is not displaying the html in Outlook, but now that I check it on my webmail it shows up just fine.  Now I need to see what outlook needs to be displayed the right way.  Thank you Frost.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.