munchkinz Posted February 2, 2011 Share Posted February 2, 2011 Hi, I have a (rather long) form on my site that when submitted send the information to me in an email. Ideally I would like to have the form only send me the information that has been filled out at current it sends everything. but for now I just need to know how I can style the email so its not one long list. also the form only comes through if an email adress is filled in it says it sends but I never recieve it. heres an example of the code for sending the email $Date = Trim(stripslashes($_POST['Date'])); $Packing = Trim(stripslashes($_POST['Packing'])); $Dismantle = Trim(stripslashes($_POST['Dismantle'])); $DismantleYes = Trim(stripslashes($_POST['DismantleYes'])); $Plumbing = Trim(stripslashes($_POST['Plumbing'])); $PlumbingYes = Trim(stripslashes($_POST['PlumbingYes'])); $LRSofa = Trim(stripslashes($_POST['LRSofa'])); $LRArmChair = Trim(stripslashes($_POST['LRArmChair'])); $LROtherChair = Trim(stripslashes($_POST['LROtherChair'])); $LRSCabinet = Trim(stripslashes($_POST['LRSCabinet'])); $LRLCabinet = Trim(stripslashes($_POST['LRLCabinet'])); $LRBookcase = Trim(stripslashes($_POST['LRBookcase'])); $LROTable = Trim(stripslashes($_POST['LROTable'])); $LRCTable = Trim(stripslashes($_POST['LRCTable'])); $LRTVStand = Trim(stripslashes($_POST['LRTVStand'])); $Body .= "Date of move: "; $Body .= $Date; $Body .= "\n"; $Body .= "Packing: "; $Body .= $Packing; $Body .= "\n"; $Body .= "Dismantle: "; $Body .= $Dismantle; $Body .= "\n"; $Body .= $DismantleYes; $Body .= "\n"; $Body .= "Plumbing: "; $Body .= $Plumbing; $Body .= "\n"; $Body .= $PlumbingYes; $Body .= "\n"; $Body .= "\n"; $Body .= "Living Room: "; $Body .= "\n"; $Body .= "Sofas: "; $Body .= $LRSofa; $Body .= "\n"; $Body .= "Arm Chairs: "; $Body .= $LRArmChair; $Body .= "\n"; $Body .= "Other Chairs: "; $Body .= $LROtherChair; $Body .= "\n"; $Body .= "Small Cabinets: "; $Body .= $LRSCabinet; $Body .= "\n"; $Body .= "Large Cabinets: "; $Body .= $LRLCabinet; $Body .= "\n"; $Body .= "Bookcases: "; $Body .= $LRBookcase; $Body .= "\n"; $Body .= "Occassional Tables: "; $Body .= $LROTable; $Body .= "\n"; $Body .= "Coffee Tables: "; $Body .= $LRCTable; $Body .= "\n"; $Body .= "TV Stand: "; // send email $success = mail($EmailTo, $Subject, $Body, "From: ". $FName ." ". $LName ." <". $Email.">"); // redirect to success page if ($success){ header ('Location: thankyou.php'); } else{ header ('Location: error.php'); } Quote Link to comment https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/ Share on other sites More sharing options...
cyberRobot Posted February 2, 2011 Share Posted February 2, 2011 You could test to see if the field is blank before adding it to the e-mail. For example: <?php ... if($Packing != '') { $Body .= "\nPacking: $Packing"; } ... ?> Quote Link to comment https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/#findComment-1168831 Share on other sites More sharing options...
munchkinz Posted February 2, 2011 Author Share Posted February 2, 2011 You could test to see if the field is blank before adding it to the e-mail. For example: <?php ... if($Packing != '') { $Body .= "\nPacking: $Packing"; } ... ?> thank you for your reply. Would I need change that for each line of $body? or add it elsewhere? also would that work for <?php ... if($LRFSTV != '0') { $Body .= "\nFlat Screen TV: $LRFSTV"; } ... ?> Where the input is a dropdown list of numbers 0-4? Quote Link to comment https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/#findComment-1168866 Share on other sites More sharing options...
cyberRobot Posted February 2, 2011 Share Posted February 2, 2011 Would I need change that for each line of $body? or add it elsewhere? Unfortunately yes, you would need to add a test for each part. Of course, you can group things like: <?php if($Plumbing != '') { $Body .= "\n"; $Body .= "Plumbing: "; $Body .= $Plumbing; } ?> also would that work for <?php ... if($LRFSTV != '0') { $Body .= "\nFlat Screen TV: $LRFSTV"; } ... ?> Where the input is a dropdown list of numbers 0-4? Yep, you can test for whatever value. Quote Link to comment https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/#findComment-1168871 Share on other sites More sharing options...
munchkinz Posted February 2, 2011 Author Share Posted February 2, 2011 Thank you very much for your help, I have done as you suggested, but I am now receiving the following error: Parse error: syntax error, unexpected '}' in /home/content/59/7338359/html/quoteform.php on line 380 I have checked and cannot see any problem, would it be possible for somebody to take a look and see if they can spot the issue, this website is live and I don't want to lose customers by having a broken website. File attached [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/#findComment-1168983 Share on other sites More sharing options...
BlueSkyIS Posted February 2, 2011 Share Posted February 2, 2011 missing semi-colon on line 379. Quote Link to comment https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/#findComment-1168986 Share on other sites More sharing options...
munchkinz Posted February 2, 2011 Author Share Posted February 2, 2011 thank you, just noticed some parenthesis are the wrong way round must be getting tired Quote Link to comment https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/#findComment-1168995 Share on other sites More sharing options...
munchkinz Posted February 2, 2011 Author Share Posted February 2, 2011 Would I need change that for each line of $body? or add it elsewhere? Unfortunately yes, you would need to add a test for each part. Of course, you can group things like: <?php if($Plumbing != '') { $Body .= "\n"; $Body .= "Plumbing: "; $Body .= $Plumbing; } ?> also would that work for <?php ... if($LRFSTV != '0') { $Body .= "\nFlat Screen TV: $LRFSTV"; } ... ?> Where the input is a dropdown list of numbers 0-4? Yep, you can test for whatever value. The first way of grouping them is working fine, but I tried the second method to try and reduce the file size but I only receive the text not the value?? Quote Link to comment https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/#findComment-1169012 Share on other sites More sharing options...
cyberRobot Posted February 2, 2011 Share Posted February 2, 2011 The first way of grouping them is working fine, but I tried the second method to try and reduce the file size but I only receive the text not the value?? Make sure you surround the output with double quotes: <?php ... $Body .= "\nFlat Screen TV: $LRFSTV"; ... ?> If you look at the output that doesn't show the value, you're probably using single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/#findComment-1169026 Share on other sites More sharing options...
coupe-r Posted February 2, 2011 Share Posted February 2, 2011 Save your fingers some scrolling.... This.... $Body .= "Date of move: "; $Body .= $Date; $Body .= "\n"; can be... $Body .= "Date of move: " . $Date . "\n"; Quote Link to comment https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/#findComment-1169027 Share on other sites More sharing options...
cyberRobot Posted February 2, 2011 Share Posted February 2, 2011 The first way of grouping them is working fine, but I tried the second method to try and reduce the file size but I only receive the text not the value?? You'll also need to make sure you didn't accidentally remove any dollar signs: <?php ... $Body .= "\nFlat Screen TV: LRFSTV"; ... ?> Note that there should be a $ before LRFSTV. I tend to make that mistake when cleaning up code in a hurry. Quote Link to comment https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/#findComment-1169029 Share on other sites More sharing options...
kenrbnsn Posted February 2, 2011 Share Posted February 2, 2011 Better yet: <?php $Body .= "Date of move: $Date\n"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/226448-how-do-you-style-a-php-mail-form/#findComment-1169030 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.