cmdrflyr Posted November 30, 2009 Share Posted November 30, 2009 Hi, I'm new to the forum and new to php. I'm not sure if I'm using the correct terminology so here it goes. I've created a page with multiple forms that when submitted get emailed to a certain address. When I receive the email it shows up as one big paragraph, but I would like it to appear similar to how the form looks. Any help would be greatly appreciated. Thanks, Jason <form method="post" form action="paytest.php"> <table width="541" border="1"> <tr> <th width="115">Day</th> <th width="73">Date</th> <th width="73">Flat Rates</th> <th width="78">Overnights</th> <th width="77">Perdiem</th> <th width="85">N #</th> </tr> <tr> <td>SUNDAY</td> <td><input type="text" size="10" maxlength="40" textarea name="date1"></td> <td><input type="text" size="10" maxlength="40" textarea name="flatrate1"></td> <td><input type="text" size="10" maxlength="40" textarea name="overnights1"></td> <td><input type="text" size="10" maxlength="40" textarea name="perdiem1"></td> <td><input type="text" size="10" maxlength="40" textarea name="tailnumber1"></td> </tr> <tr> <td>MONDAY</td> <td><input type="text" size="10" maxlength="40" name="date2"></td> <td><input type="text" size="10" maxlength="40" name="flatrate2"></td> <td><input type="text" size="10" maxlength="40" name="overnights2"></td> <td><input type="text" size="10" maxlength="40" name="perdiem2"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber2"></td> </tr> <tr> <td>TUESDAY</td> <td><input type="text" size="10" maxlength="40" name="date3"></td> <td><input type="text" size="10" maxlength="40" name="flatrate3"></td> <td><input type="text" size="10" maxlength="40" name="overnights3"></td> <td><input type="text" size="10" maxlength="40" name="perdiem3"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber3"></td> </tr> <tr> <td>WEDNESDAY</td> <td><input type="text" size="10" maxlength="40" name="date4"></td> <td><input type="text" size="10" maxlength="40" name="flatrate4"></td> <td><input type="text" size="10" maxlength="40" name="overnights4"></td> <td><input type="text" size="10" maxlength="40" name="perdiem4"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber4"></td> </tr> <tr> <td>THURSDAY</td> <td><input type="text" size="10" maxlength="40" name="date5"></td> <td><input type="text" size="10" maxlength="40" name="flatrate5"></td> <td><input type="text" size="10" maxlength="40" name="overnights5"></td> <td><input type="text" size="10" maxlength="40" name="perdiem5"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber5"></td> </tr> <tr> <td>FRIDAY</td> <td><input type="text" size="10" maxlength="40" name="date6"></td> <td><input type="text" size="10" maxlength="40" name="flatrate6"></td> <td><input type="text" size="10" maxlength="40" name="overnights6"></td> <td><input type="text" size="10" maxlength="40" name="perdiem6"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber6"></td> </tr> <tr> <td>SATURDAY</td> <td><input type="text" size="10" maxlength="40" name="date7"></td> <td><input type="text" size="10" maxlength="40" name="flatrate7"></td> <td><input type="text" size="10" maxlength="40" name="overnights7"></td> <td><input type="text" size="10" maxlength="40" name="perdiem7"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber7"></td> </tr> <tr> <td>SUNDAY</td> <td><input type="text" size="10" maxlength="40" name="date8"></td> <td><input type="text" size="10" maxlength="40" name="flatrate8"></td> <td><input type="text" size="10" maxlength="40" name="overnights8"></td> <td><input type="text" size="10" maxlength="40" name="perdiem8"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber8"></td> </tr> <tr> <td>MONDAY</td> <td><input type="text" size="10" maxlength="40" name="date9"></td> <td><input type="text" size="10" maxlength="40" name="flatrate9"></td> <td><input type="text" size="10" maxlength="40" name="overnights9"></td> <td><input type="text" size="10" maxlength="40" name="perdiem9"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber9"></td> </tr> <tr> <td>TUESDAY</td> <td><input type="text" size="10" maxlength="40" name="date10"></td> <td><input type="text" size="10" maxlength="40" name="flatrate10"></td> <td><input type="text" size="10" maxlength="40" name="overnights10"></td> <td><input type="text" size="10" maxlength="40" name="perdiem10"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber10"></td> </tr> <tr> <td>WEDNESDAY</td> <td><input type="text" size="10" maxlength="40" name="date11"></td> <td><input type="text" size="10" maxlength="40" name="flatrate11"></td> <td><input type="text" size="10" maxlength="40" name="overnights11"></td> <td><input type="text" size="10" maxlength="40" name="perdiem11"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber11"></td> </tr> <tr> <td>THURSDAY</td> <td><input type="text" size="10" maxlength="40" name="date12"></td> <td><input type="text" size="10" maxlength="40" name="flatrate12"></td> <td><input type="text" size="10" maxlength="40" name="overnights12"></td> <td><input type="text" size="10" maxlength="40" name="perdiem12"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber12"></td> </tr> <tr> <td>FRIDAY</td> <td><input type="text" size="10" maxlength="40" name="date13"></td> <td><input type="text" size="10" maxlength="40" name="flatrate13"></td> <td><input type="text" size="10" maxlength="40" name="overnights13"></td> <td><input type="text" size="10" maxlength="40" name="perdiem13"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber13"></td> </tr> <tr> <td>SATURDAY</td> <td><input type="text" size="10" maxlength="40" name="date14"></td> <td><input type="text" size="10" maxlength="40" name="flatrate14"></td> <td><input type="text" size="10" maxlength="40" name="overnights14"></td> <td><input type="text" size="10" maxlength="40" name="perdiem14"></td> <td><input type="text" size="10" maxlength="40" name="tailnumber14"></td> </tr> </table> <input type="submit" value="Send"> <br /> </form> paytest.php <?php $to = "test@test.com" ; $subject = "paysheet" ; $text.='date:'.$_REQUEST["date1"] ; $text.='flat rate:'.$_REQUEST["flatrate1"] ; $text.='over nights:'.$_REQUEST["overnights1"] ; $text.='perdiem:'.$_REQUEST["perdiem1"] ; $text.='tail number:'.$_REQUEST["tailnumber1"] ; $text.='date:'.$_REQUEST["date2"] ; $text.='flat rate:'.$_REQUEST["flatrate2"]. "<br><br>" ; $text.='over nights:'.$_REQUEST["overnights2"] ; $text.='perdiem:'.$_REQUEST["perdiem2"] ; $text.='tail number:'.$_REQUEST["tailnumber2"] ; $text.='date:'.$_REQUEST["date3"] ; $text.='flat rate:'.$_REQUEST["flatrate3"] ; $text.='over nights:'.$_REQUEST["overnights3"] ; $text.='perdiem:'.$_REQUEST["perdiem3"] ; $text.='tail number:'.$_REQUEST["tailnumber3"] ; $text.='date:'.$_REQUEST["date4"] ; $text.='flat rate:'.$_REQUEST["flatrate4"] ; $text.='over nights:'.$_REQUEST["overnights4"] ; $text.='perdiem:'.$_REQUEST["perdiem4"] ; $text.='tail number:'.$_REQUEST["tailnumber4"] ; $text.='date:'.$_REQUEST["date5"] ; $text.='flat rate:'.$_REQUEST["flatrate5"] ; $text.='over nights:'.$_REQUEST["overnights5"] ; $text.='perdiem:'.$_REQUEST["perdiem5"] ; $text.='tail number:'.$_REQUEST["tailnumber5"] ; $text.='date:'.$_REQUEST["date6"] ; $text.='flat rate:'.$_REQUEST["flatrate6"] ; $text.='over nights:'.$_REQUEST["overnights6"] ; $text.='perdiem:'.$_REQUEST["perdiem6"] ; $text.='tail number:'.$_REQUEST["tailnumber6"] ; $text.='date:'.$_REQUEST["date7"] ; $text.='flat rate:'.$_REQUEST["flatrate7"] ; $text.='over nights:'.$_REQUEST["overnights7"] ; $text.='perdiem:'.$_REQUEST["perdiem7"] ; $text.='tail number:'.$_REQUEST["tailnumber7"] ; $text.='date:'.$_REQUEST["date8"] ; $text.='flat rate:'.$_REQUEST["flatrate8"] ; $text.='over nights:'.$_REQUEST["overnights8"] ; $text.='perdiem:'.$_REQUEST["perdiem8"] ; $text.='tail number:'.$_REQUEST["tailnumber8"] ; $text.='date:'.$_REQUEST["date9"] ; $text.='flat rate:'.$_REQUEST["flatrate9"] ; $text.='over nights:'.$_REQUEST["overnights9"] ; $text.='perdiem:'.$_REQUEST["perdiem9"] ; $text.='tail number:'.$_REQUEST["tailnumber9"] ; $text.='date:'.$_REQUEST["date10"] ; $text.='flat rate:'.$_REQUEST["flatrate10"] ; $text.='over nights:'.$_REQUEST["overnights10"] ; $text.='perdiem:'.$_REQUEST["perdiem10"] ; $text.='tail number:'.$_REQUEST["tailnumber10"] ; $text.='date:'.$_REQUEST["date11"] ; $text.='flat rate:'.$_REQUEST["flatrate11"] ; $text.='over nights:'.$_REQUEST["overnights11"] ; $text.='perdiem:'.$_REQUEST["perdiem11"] ; $text.='tail number:'.$_REQUEST["tailnumber11"] ; $text.='date:'.$_REQUEST["date12"] ; $text.='flat rate:'.$_REQUEST["flatrate12"] ; $text.='over nights:'.$_REQUEST["overnights12"] ; $text.='perdiem:'.$_REQUEST["perdiem12"] ; $text.='tail number:'.$_REQUEST["tailnumber12"] ; $text.='date:'.$_REQUEST["date13"] ; $text.='flat rate:'.$_REQUEST["flatrate13"] ; $text.='over nights:'.$_REQUEST["overnights13"] ; $text.='perdiem:'.$_REQUEST["perdiem13"] ; $text.='tail number:'.$_REQUEST["tailnumber13"] ; $text.='date:'.$_REQUEST["date14"] ; $text.='flat rate:'.$_REQUEST["flatrate14"] ; $text.='over nights:'.$_REQUEST["overnights14"] ; $text.='perdiem:'.$_REQUEST["perdiem14"] ; $text.='tail number:'.$_REQUEST["tailnumber14"] ; $header = "from: Jason Smith" ; $sent = mail($to, $subject, $text, $headers) ; if($sent) {print "Your pay sheet was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/183370-line-break/ Share on other sites More sharing options...
DiscoTrio Posted November 30, 2009 Share Posted November 30, 2009 Inserting <br> is like hitting enter key...if that helps. Quote Link to comment https://forums.phpfreaks.com/topic/183370-line-break/#findComment-967912 Share on other sites More sharing options...
MadTechie Posted November 30, 2009 Share Posted November 30, 2009 As the email is NOT HTML, Your need to add a NewLine "\n" ie $text.='date:'.$_REQUEST["date1"] ; $text.='flat rate:'.$_REQUEST["flatrate1"]."\n"; $text.='over nights:'.$_REQUEST["overnights1"]."\n"; $text.='perdiem:'.$_REQUEST["perdiem1"]."\n"; $text.='tail number:'.$_REQUEST["tailnumber1"]."\n"; Quote Link to comment https://forums.phpfreaks.com/topic/183370-line-break/#findComment-967913 Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2009 Share Posted November 30, 2009 Slightly off topic, but you do know that if you used php to produce the form and used arrays for the fields, that both the form and the form processing code could be reduced to a small number of lines. Quote Link to comment https://forums.phpfreaks.com/topic/183370-line-break/#findComment-967937 Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2009 Share Posted November 30, 2009 And in fact, using php, will make any changes to the form or the form processing code simpler because you will only need to make the change once instead of 14 times - The form: <?php $days = array(); // array of day names $days[] = 'SUNDAY'; $days[] = 'MONDAY'; $days[] = 'TUESDAY'; $days[] = 'WEDNESDAY'; $days[] = 'THURSDAY'; $days[] = 'FRIDAY'; $days[] = 'SATURDAY'; $num_weeks = 2; // your code appears to handle two weeks $content = "<form method='post' form action='paytest.php'> <table width='541' border='1'> <tr> <th width='115'>Day</th> <th width='73'>Date</th> <th width='73'>Flat Rates</th> <th width='78'>Overnights</th> <th width='77'>Perdiem</th> <th width='85'>N #</th> </tr>"; $index = 1; // start various index values at 1 // loop for the correct number of weeks for($x=1;$x<=$num_weeks;$x++){ // iterate over each day in the week foreach($days as $day){ $content .= "<tr> <td>$day</td> <td><input type='text' size='10' maxlength='40' textarea name='date[$index]'></td> <td><input type='text' size='10' maxlength='40' textarea name='flatrate[$index]'></td> <td><input type='text' size='10' maxlength='40' textarea name='overnights[$index]'></td> <td><input type='text' size='10' maxlength='40' textarea name='perdiem[$index]'></td> <td><input type='text' size='10' maxlength='40' textarea name='tailnumber[$index]'></td> </tr>"; $index++; } } $content .= "</table> <input type='submit' value='Send'> <br /> </form>"; echo $content; ?> The form processing code: <?php $text = ''; $count = count($_POST['date']); // loop through each (14) sets of data for($x=1;$x<=$count;$x++){ $text.="date:{$_POST["date"][$x]}\n"; $text.="flat rate:{$_POST["flatrate"][$x]}\n"; $text.="over nights:{$_POST["overnights"][$x]}\n"; $text.="perdiem:{$_POST["perdiem"][$x]}\n"; $text.="tail number:{$_POST["tailnumber"][$x]}\n"; } // echo nl2br($text); // testing testing... $to = "test@test.com" ; $subject = "paysheet" ; $header = "from: Jason Smith" ; $sent = mail($to, $subject, $text, $header) ; if($sent){ print "Your pay sheet was sent successfully"; } else { print "We encountered an error sending your mail"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/183370-line-break/#findComment-967949 Share on other sites More sharing options...
cmdrflyr Posted November 30, 2009 Author Share Posted November 30, 2009 That's great, Thank you for the short cuts. have a lot to learn. the arrays cut down a lot of code. Thanks again. Jason Quote Link to comment https://forums.phpfreaks.com/topic/183370-line-break/#findComment-967956 Share on other sites More sharing options...
keldorn Posted November 30, 2009 Share Posted November 30, 2009 I heard you shouldn't $_REQUEST , you should be more specific and use $_GET or $_POST. Quote Link to comment https://forums.phpfreaks.com/topic/183370-line-break/#findComment-967960 Share on other sites More sharing options...
Daniel0 Posted November 30, 2009 Share Posted November 30, 2009 I heard you shouldn't $_REQUEST , you should be more specific and use $_GET or $_POST. It's generally good to know the source of your data, but there might be cases where you don't particularly care if some variable is passed using GET or POST. I can't think of any good example right now. Even better would be to use filter_input. Quote Link to comment https://forums.phpfreaks.com/topic/183370-line-break/#findComment-968040 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.