iconicCreator Posted January 27, 2009 Share Posted January 27, 2009 Just curious, is it possible to format the information that is been submitted in a form? Say for example: I want to make things like $firstName or all the fields variables or name appeared bold in the submitted e-mail. Or I want a space at the bottom of the textarea. Right now the text being submitted extends to the walls of the browser both horizontal and vertical, it hits the bottom of the page. I'm researching this for answers but if anyone can tell me, it would be wonderful. IC Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/ Share on other sites More sharing options...
MatthewJ Posted January 27, 2009 Share Posted January 27, 2009 If you're asking if it can be formatted in an email you or someone receives then yes, send html email instead of plain text See example 4 http://www.php.net/manual/en/function.mail.php Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-747800 Share on other sites More sharing options...
iconicCreator Posted January 27, 2009 Author Share Posted January 27, 2009 If you're asking if it can be formatted in an email you or someone receives then yes, send html email instead of plain text See example 4 http://www.php.net/manual/en/function.mail.php Let me explain further. I do not want to format the entire form but the labels that comes before each variable colored red in the code below. I need these elements to appeared bold or a different color when the e-mail is recieved. Is this possible? $to = 'mymail.com'; $subject = 'Canned soup evaluation report'; $msg = "First Name: $firstName\n\n" . "Last Name: $lastName\n\n" . "E-Mail: $email\n\n" . "Comments: $messageComments"; IC Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748010 Share on other sites More sharing options...
DeanWhitehouse Posted January 27, 2009 Share Posted January 27, 2009 Yes, use a span tag on them with some css to change the colour Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748011 Share on other sites More sharing options...
iconicCreator Posted January 28, 2009 Author Share Posted January 28, 2009 Yes, use a span tag on them with some css to change the colour Well how do I applied the span tag with out screwing up everything? Because when I applied the <b> tag, it shows up in the e-mail as text. IC Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748084 Share on other sites More sharing options...
.josh Posted January 28, 2009 Share Posted January 28, 2009 you have to specify your content as having html in the email header. google email headers. But even then, most people have the choice to have their email allow html content, so there's only so much you can do. Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748085 Share on other sites More sharing options...
MadTechie Posted January 28, 2009 Share Posted January 28, 2009 If you want to use HTML in an email your need to tell the email client your data contains HTML data, you can use phpmailer (google it) or try this <?php function send_email($from, $to, $subject, $message){ $headers = "From: ".$from."\r\n"; $headers .= "Reply-To: ".$from."\r\n"; $headers .= "Return-Path: ".$from."\r\n"; $headers .= "Content-type: text/html\r\n"; if (mail($to,$subject,$message,$headers) ) { echo "email sent"; } else { echo "email couldn't be sent"; } } $subject = "Helloooo!"; $message .= "<html><body>"; $message .= "<b>Hey! How are you today?</b>"; $message .= "<br>Regards"; $message .= "</body></html>"; send_email("youraddress@domain.com", "recpeient@domain.com", $subject , $message); ?> Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748091 Share on other sites More sharing options...
iconicCreator Posted January 28, 2009 Author Share Posted January 28, 2009 If you want to use HTML in an email your need to tell the email client your data contains HTML data, you can use phpmailer (google it) or try this <?php function send_email($from, $to, $subject, $message){ $headers = "From: ".$from."\r\n"; $headers .= "Reply-To: ".$from."\r\n"; $headers .= "Return-Path: ".$from."\r\n"; $headers .= "Content-type: text/html\r\n"; if (mail($to,$subject,$message,$headers) ) { echo "email sent"; } else { echo "email couldn't be sent"; } } $subject = "Helloooo!"; $message .= "<html><body>"; $message .= "<b>Hey! How are you today?</b>"; $message .= "<br>Regards"; $message .= "</body></html>"; send_email("youraddress@domain.com", "recpeient@domain.com", $subject , $message); ?> Are we talking about the same thing? Because I'm not talking about sending an e-mail, what I'm talking about is processing a form with PHP. I already have the form setup and working. Just a little confused, please bear with my ignorance. IC Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748205 Share on other sites More sharing options...
.josh Posted January 28, 2009 Share Posted January 28, 2009 Are we talking about the same thing? Because I'm not talking about sending an e-mail, what I'm talking about is processing a form with PHP. Really? Because in all 3 of your previous posts, you mention.... I want to make things like $firstName or all the fields variables or name appeared bold in the submitted e-mail. I need these elements to appeared bold or a different color when the e-mail is recieved. Because when I applied the <b> tag, it shows up in the e-mail as text. Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748207 Share on other sites More sharing options...
MadTechie Posted January 28, 2009 Share Posted January 28, 2009 if its just a form.. then try the CSS section ??? but i guess everyone thought you was talking about sending emails.. Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748210 Share on other sites More sharing options...
iconicCreator Posted January 28, 2009 Author Share Posted January 28, 2009 if its just a form.. then try the CSS section ??? but i guess everyone thought you was talking about sending emails.. I apologized if I'm causing confusion. This is what I have. An html form that contained a POST method sent to a php page or script. In the php page or script there are variables like this. $Message = "First Name: $firstName"; This gets the first name and sent it to an e-mail address when the user click the submit button on the html form. What I'm trying to accomplished is to format the "First Name: label, not the name it self, so that when I recieved the e-mail the labels in the e-mail, Eg: First Name: appeared in bold. Like this. First Name: Wayne Last Name: Newton E-mail: wayne@newton.com I'm a novice to php and I'm sorry if this makes no sense. IC Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748247 Share on other sites More sharing options...
.josh Posted January 28, 2009 Share Posted January 28, 2009 You use normal html markup to make it bold, like so: $Message = "<b>First Name:</b> $firstName"; Or you can use <strong> tags or style it. Point is, you treat your email content just like outputting and formatting stuff on a web page. And as mentioned, in order to get something to show up bold in your email (or italicized, or any other markup), you have to specify html content in your email header. Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748262 Share on other sites More sharing options...
iconicCreator Posted January 28, 2009 Author Share Posted January 28, 2009 You use normal html markup to make it bold, like so: $Message = "<b>First Name:</b> $firstName"; Or you can use <strong> tags or style it. Point is, you treat your email content just like outputting and formatting stuff on a web page. And as mentioned, in order to get something to show up bold in your email (or italicized, or any other markup), you have to specify html content in your email header. I understand what you mean, what I don't understand is how I go about specifying HTML content in the e-mail header. Thanks for your patience - really appreciate all the help. Below is the entire PHP page/code. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Canned soup evaluation</title> <style type="text/css"> <!-- .confirmation { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 16px; width: 780px; border: 1px solid #999999; background-color: #CCCCCC; text-align: center; margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; padding-top: 80px; padding-right: 0px; padding-bottom: 80px; padding-left: 0px; } .sendersName { font-weight: bold; color: #FFFFFF; } --> </style> </head> <body> <?php //FORM INPUT COLLECTION $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $email = $_POST['email']; $soupPreference = $_POST['soupPreference']; $howMany = $_POST['howMany']; $changes = $_POST['changes']; $messageComments = $_POST['messageComments']; //FORM PROCESSOR $to = 'my@my.com'; $subject = 'Canned soup evaluation report'; $msg = "<b>First Name:</b> $firstName\n\n" . "Last Name: $lastName\n\n" . "E-Mail: $email\n\n" . "Do you like canned soup? $soupPreference\n\n" . "How many canned soup do you eat in a day? $howMany\n\n" . "What changes or suggestions would you recommend: $changes\n\n" . "Comments: $messageComments\n\n"; $msg = wordwrap($msg, 100); mail($to, $subject, $msg, 'From: '.$firstName.' '.$lastName.' <'.$email.'>'); ?> <?php $myVar = "Thanks <span class=\"sendersName\"> $firstName</span> for evaluating our product, we will contact you within 24 hours."; ?> <div class="confirmation"><?php echo $myVar; ?></div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748285 Share on other sites More sharing options...
.josh Posted January 28, 2009 Share Posted January 28, 2009 MadTechie showed you how. Look at his $header variable, what's in it, where he puts it. Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748394 Share on other sites More sharing options...
lordshoa Posted January 28, 2009 Share Posted January 28, 2009 msg = "<b> <font color=red> First Name: </font> </b> $firstName\n\n" . "<font color=red> Last Name: </font> $lastName\n\n" . "<font color=red> E-Mail: </font> $email\n\n" . "Do you like canned soup? $soupPreference\n\n" . "How many canned soup do you eat in a day? $howMany\n\n" . "What changes or suggestions would you recommend: $changes\n\n" . "Comments: $messageComments\n\n"; Maybe some thing like that or with could be done with css. Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748423 Share on other sites More sharing options...
iconicCreator Posted January 28, 2009 Author Share Posted January 28, 2009 msg = "<b> <font color=red> First Name: </font> </b> $firstName\n\n" . "<font color=red> Last Name: </font> $lastName\n\n" . "<font color=red> E-Mail: </font> $email\n\n" . "Do you like canned soup? $soupPreference\n\n" . "How many canned soup do you eat in a day? $howMany\n\n" . "What changes or suggestions would you recommend: $changes\n\n" . "Comments: $messageComments\n\n"; Maybe some thing like that or with could be done with css. I tried exactly that as I'm an advance CSS user. I tried wrapping it in a span tag, using the strong tag and the bold tag, every tag I tried will show up in the e-mail. Bottom line the form is working perfectly but as a way to expand my knowledge I thought I could get this accomplish. I know it sounds simple but it's like explaining how to fly a jet to someone who has never flown a jet or even seen one, it gets completely. I have read on headers and I keep seeing headers, goggling headers but still trying to understand how I can use that in my specific setting or form. One of the confusing problem is, I have tons of books on PHP some of them pretty useless. And it gets very confusing because everyone tells you to do the same thing in a different way. But I'm going to move on and hopefully come back to this later - now I'm going to learn how to validate the form. But thanks for your effort - I guess I could just buy a script or download a script for free but I hate that method - it only makes you lazy in the end. I'll keep trying and if PHP beomes too difficult, I'll go be a plumber! ;D IC Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748559 Share on other sites More sharing options...
Guest Posted January 28, 2009 Share Posted January 28, 2009 I think there's been a series of misunderstandings. They answered your question, but you probably think the problem is somewhere else. But the issue is not in the formatting of the information itself as it comes from the form, but in the way it is sent. There are three steps to this process: 1. This form will post to your script: <form action="script.php" method="post"> First name: <input name="firstname" type="text" /> Last name: <input name="lastname" type="text" /> </form> 2. The script receives, validates and formats it into HTML (assume they submitted Billy and Bob as firstname/lastname) <p><strong>First name:</strong> Billy</p> <p><strong>Last name:</strong> Bob</p> 3. The script sends that in an email. --- #3 is where your problem is. You probably believe otherwise, that's why you dismissed MadTechie's solution. Now 1 and 2 are straightforward. But you said that your tags appear as text in your emails, that is because, by default, emails are sent from PHP in "plain text" format. Meaning it doesn't know what to do with html tags, so it simply sends it as literal text. The result is any formatting cannot be seen in the email. To fix this, you have to tell PHP that this is an HTML email. And in order to do that, you follow what MadTechie suggested. $headers = "From: ".$from."\r\n"; $headers .= "Reply-To: ".$from."\r\n"; $headers .= "Return-Path: ".$from."\r\n"; $headers .= "Content-type: text/html\r\n"; if (mail($to,$subject,$message,$headers) ) { echo "email sent"; } else { echo "email couldn't be sent"; } Headers make up "meta" information for the email. Telling whatever reads the email how to read it. Notice the 4th line in the code above. That line "Content-type: text/html" tells whatever reads that email (an email reader) that this is an email containing HTML tags--and it should be formatted as such. I hope I resolved some of your confusion. Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748591 Share on other sites More sharing options...
iconicCreator Posted January 28, 2009 Author Share Posted January 28, 2009 I think there's been a series of misunderstandings. They answered your question, but you probably think the problem is somewhere else. But the issue is not in the formatting of the information itself as it comes from the form, but in the way it is sent. There are three steps to this process: 1. This form will post to your script: <form action="script.php" method="post"> First name: <input name="firstname" type="text" /> Last name: <input name="lastname" type="text" /> </form> 2. The script receives, validates and formats it into HTML (assume they submitted Billy and Bob as firstname/lastname) <p><strong>First name:</strong> Billy</p> <p><strong>Last name:</strong> Bob</p> 3. The script sends that in an email. --- #3 is where your problem is. You probably believe otherwise, that's why you dismissed MadTechie's solution. Now 1 and 2 are straightforward. But you said that your tags appear as text in your emails, that is because, by default, emails are sent from PHP in "plain text" format. Meaning it doesn't know what to do with html tags, so it simply sends it as literal text. The result is any formatting cannot be seen in the email. To fix this, you have to tell PHP that this is an HTML email. And in order to do that, you follow what MadTechie suggested. $headers = "From: ".$from."\r\n"; $headers .= "Reply-To: ".$from."\r\n"; $headers .= "Return-Path: ".$from."\r\n"; $headers .= "Content-type: text/html\r\n"; if (mail($to,$subject,$message,$headers) ) { echo "email sent"; } else { echo "email couldn't be sent"; } Headers make up "meta" information for the email. Telling whatever reads the email how to read it. Notice the 4th line in the code above. That line "Content-type: text/html" tells whatever reads that email (an email reader) that this is an email containing HTML tags--and it should be formatted as such. I hope I resolved some of your confusion. I'm not blaming anyone, or saying they did not answer my questions. So far everyone in here are being very patient and helpful. I am not dismissing anything. How can I dismissed something when I don't even know what it is? I don't' know what an array is, I don't know what a header, all I did was what I have been learning in here. I have learn all I know from asking questions. The problem here is I'm not fully understand and trying to put together what is being explained to me. Anyway, I'm back to the books - thanks very much for your time and efforts. IC Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-748602 Share on other sites More sharing options...
Guest Posted January 29, 2009 Share Posted January 29, 2009 No problem! Sorry if I made it sound like I was accusing you, it wasn't my intention. Perhaps dismissed was a poor choice of word. But either way, good luck! Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-750153 Share on other sites More sharing options...
MatthewJ Posted January 29, 2009 Share Posted January 29, 2009 Well, you're obviously giving it a heck of an effort, this is a working script for what you want to do. It is very much simplified but works <?php if(isset($_POST['submit'])) { // Send the email formatted as an html email $to = 'your email here'; $from = 'test@test.com'; // you could use an email field and let the person put their own email here $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $message = '<strong>This</strong> is an html <i>email</i> sent by<br /><br /><strong>Name:</strong> $firstname $lastname'; $headers = "From: ".$from."\r\n"; $headers .= "Reply-To: ".$from."\r\n"; $headers .= "Return-Path: ".$from."\r\n"; $headers .= "Content-type: text/html\r\n"; if (mail($to,$subject,$message,$headers) ) { echo "email sent"; } else { echo "email couldn't be sent"; } }else { // Show the form } ?> <form action="" method="post"> First name: <input name="firstname" type="text" /> <br /> Last name: <input name="lastname" type="text" /> <br /> <input type="submit" value="submit mail" name="submit" /> </form> Just put your email in the "your email here" line and run it.. it should work, then break it apart and make it your own Hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/142665-is-it-possible-to-format-the-textinfo-being-submitted-in-a-php-form/#findComment-750168 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.