stvs Posted August 9, 2007 Share Posted August 9, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/64123-processing-form-data-and-emailing-it-in-html-format/ Share on other sites More sharing options...
frost Posted August 9, 2007 Share Posted August 9, 2007 Can you post the code for the form you are using? Quote Link to comment https://forums.phpfreaks.com/topic/64123-processing-form-data-and-emailing-it-in-html-format/#findComment-319576 Share on other sites More sharing options...
m1a2x3x7 Posted August 9, 2007 Share Posted August 9, 2007 are you requesting this page once the form is submitted? or is the form included on the php page? Quote Link to comment https://forums.phpfreaks.com/topic/64123-processing-form-data-and-emailing-it-in-html-format/#findComment-319581 Share on other sites More sharing options...
stvs Posted August 9, 2007 Author Share Posted August 9, 2007 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] Quote Link to comment https://forums.phpfreaks.com/topic/64123-processing-form-data-and-emailing-it-in-html-format/#findComment-319585 Share on other sites More sharing options...
frost Posted August 9, 2007 Share Posted August 9, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/64123-processing-form-data-and-emailing-it-in-html-format/#findComment-319591 Share on other sites More sharing options...
m1a2x3x7 Posted August 9, 2007 Share Posted August 9, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/64123-processing-form-data-and-emailing-it-in-html-format/#findComment-319601 Share on other sites More sharing options...
stvs Posted August 9, 2007 Author Share Posted August 9, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/64123-processing-form-data-and-emailing-it-in-html-format/#findComment-319681 Share on other sites More sharing options...
frost Posted August 9, 2007 Share Posted August 9, 2007 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); Quote Link to comment https://forums.phpfreaks.com/topic/64123-processing-form-data-and-emailing-it-in-html-format/#findComment-319729 Share on other sites More sharing options...
stvs Posted August 9, 2007 Author Share Posted August 9, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/64123-processing-form-data-and-emailing-it-in-html-format/#findComment-319783 Share on other sites More sharing options...
frost Posted August 10, 2007 Share Posted August 10, 2007 I have tested my code in outlook and it seemed to work just fine. Do you have any settings that could prevent the HTML from showing up? p.s. Remember to mark the topic as solved if it is so. Quote Link to comment https://forums.phpfreaks.com/topic/64123-processing-form-data-and-emailing-it-in-html-format/#findComment-320628 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.