brantonlj87 Posted June 24, 2015 Share Posted June 24, 2015 Okay I have a currently working form on my website, it is a request a reservation form. Then I have a captcha image to stop spam and a captcha.php file which repeats the information to the client on the thank you page as well as sends an email to me with the information from the request. What I am looking to do is simply format the information when it comes into my email a simple table would work. I found a snippet of code online and I altered it to fit my forms information. I changed the code and uploaded it then gave the request a try and them email still sends but the whole thing is blank. Thank god I kept the original code. Can someone please help me format this information so it will come to my email in an easier to read format. Here is the form code: <form name="reserve" method="post" action="captcha/captcha.php"> <table style="width: 100%"> <tr> <td class="auto-style16" colspan="2"> <h3><span class="header1">Make a Reservation</span></h3> </td> </tr> <tr> <td class=" text" colspan="2"><span class="body1"></span>Request a reservation for one of our San Juan Island Cruises. One of our cruise professionals will follow up with you via e-mail or phone to confirm your reservation as soon as possible.<br>Please bear in mind that confirmation may take <b>up to 72 hours</b>.</span> </td> </tr> <tr> <td class="auto-style17"> <label for="name"id="name">Full Name:</label> <input type="hidden" name="recipents"> </td> <td class="auto-style17"><input name="name" type="text" /> </td> </tr> <tr> <td class="auto-style17"><label for="address" id="address">Address:</label> </td> <td class="auto-style17"> <input name="address" type="text" /> </td> </tr> <tr> <td class="auto-style17" style="height: 26px"><label for="address2" id="address2">Address 2:</label></td> <td class="auto-style17" style="height: 26px"> <input name="address2" type="text" /></td> </tr> <tr> <td class="auto-style17"><label for="city" name="city "id="city">City:</label></td> <td class="auto-style17"> <input name="city" type="text" ></td> </tr> <tr> <td class="auto-style17"><label for="state"name="state"id="state">State/Province: </label></td> <td class="auto-style17"> <input name="state" type="text" ></td> </tr> <tr> <td class="auto-style17" style="height: 26px"><label for="zipcode" name="zipcode"id="zipcode">Zip/Postal Code:</label></td> <td class="auto-style17" style="height: 26px"> <input name="zipcode" type="text" ></td> </tr> <tr> <td class="auto-style17"><label for="phone" name="phone"id="phone">Phone Number*:</label></td> <td class="auto-style17"><input name="phone" type="text" ></td> </tr> <tr> <td class="auto-style17"><label for="email"id="email">Email Address*: </label></td> <td class="auto-style17"> <input name="email" type="text" /> </td> </tr> <tr> <td class="auto-style17" colspan="2"><span class="tiny"><br><br>* We will only use your phone number or email address to contact you regarding your Reservation Request. For more information, please refer to our Privacy Policy<br><br> </span> </td> </tr> <tr> <td colspan="2" class="auto-style16"><span class="big"> Cruise Selection</span></td> </tr> <tr> <td class="auto-style17" style="height: 26px"><label for="passnumber" id="passnumber">Number of Passangers: </label></td> <td class="auto-style17" style="height: 26px"><input name="passnumber" type="text" /> </td> </tr> <tr> <td class="auto-style17" style="height: 26px"><label for="cabin_type" id="cabin_type">Cabin Type:</label> </td> <td class="auto-style17" style="height: 26px"> <select name="cabin_type"> <OPTION value="">Select Cabin Type</OPTION> <OPTION value="Twin" id="twin">Twin Beb</OPTION> <OPTION value="Queen" id="queen">Queen Bed</OPTION> <OPTION value="Double" id="double">Double Beb</OPTION> </select> </td> </tr> <tr> <td class="auto-style17" style="height: 26px"><label for="cruise_1" id="cruise_1">2015 Cruise Date 1st choice:</label></td> <td class="auto-style17" style="height: 26px"> <select name="cruise_1"> <OPTION value="">Select Cruise Date</OPTION> <OPTION value="9/24/15-10/01/15" id="9/24/15-10/01/15">September 24 - October 1, 2015</OPTION> <OPTION value="10/2/15-10/09/15" id="10/2/15-10/09/15">October is Full</OPTION> </select> </td> </tr> <tr> <td class="auto-style17" style="height: 26px"><label for="cruise_2" id="cruise_2">2015 Cruise Date 2nd choice</label></td> <td class="auto-style17" style="height: 26px"> <select name="cruise_2"> <OPTION value="">Select Cruise Date</OPTION> <OPTION value="9/24/15-10/01/15" id="9/24/15-10/01/15">September 24 - October 1, 2015</OPTION> <OPTION value="10/2/15-10/09/15" id="10/2/15-10/09/15">October is Full</OPTION> </select> </td> </tr> <tr> <td class="auto-style17" style="height: 26px"> </td> <td class="auto-style17" style="height: 26px"> </td> </tr> <tr> <td class="auto-style17" style="height: 26px" colspan="2"> <label for="comments" id="comments">Please give us the names of all guests and cabins needed. Please list any questions you may have in the textbox below:</label> </td> </tr> <tr> <td class="auto-style17" style="height: 26px" colspan="2"> <textarea name="comments" cols="25" rows="5" id="comments"></textarea></td> </tr> <tr> <td class="auto-style17" style="height: 26px">Please enter the code you see below.</td> <td class="auto-style17" style="height: 26px"></td> </tr> <tr> <td class="auto-style17" style="height: 26px"><img src="captcha/captcha_image.php" /></td> <td class="auto-style17" style="height: 26px"><input type="text" name="security" id="security"></td> </tr> <tr> <td class="auto-style18" style="height: 26"><br><INPUT TYPE="submit" name="submit" id="submit" value="Submit"><br><br></td> <td class="auto-style18" style="height: 26"><br><br><br></td> </tr> </table> Here is my original captcha.php file <? if ($_SERVER["REQUEST_METHOD"] <> "POST") die("You can only reach this page by posting from the html form"); // *** The text input will come in through the variable $_POST["captcha_input"], // while the correct answer is stored in the cookie $_COOKIE["pass"] *** if ($_POST["security"] == $_SESSION["pass"]) { // *** They passed the test! *** // *** This is where you would post a comment to your database, etc *** echo "Correct! You have passed the captcha test. <br><br>"; echo "You information input has been sent <br><br>"; echo "This is what you sent <br><br>"; echo "Name: \"" . $_POST["name"] . "\" <br>"; echo "Address: \"" . $_POST["address"] . "\" <br>"; echo "Address2: \"" . $_POST["address2"] . "\" <br>"; echo "City: \"" . $_POST["city"] . "\" <br>"; echo "State: \"" . $_POST["state"] . "\" <br>"; echo "Zipcode: \"" . $_POST["zipcode"] . "\" <br>"; echo "Phone: \"" . $_POST["phone"] . "\" <br>"; echo "Email: \"" . $_POST["email"] . "\" <br>"; echo "Passenger_Number: \"" . $_POST["passnumber"] . "\" <br>"; echo "Cabin_type: \"" . $_POST["cabin_type"] . "\" <br>"; echo "Cruise_1: \"" . $_POST["cruise_1"] . "\" <br>"; echo "Cruise_2: \"" . $_POST["cruise_2"] . "\" <br>"; echo "comments: \"" . $_POST["comments"] . "\" <br>"; //sends email via php to the following address $mailuser = "form.one@sanjuanislandcruises.com"; //echo 'default chosen address: '.$mailuser; $header = "Return-Path: ".$mailuser."\r\n"; $header .= "From: San Juan Reservations <".$mailuser.">\r\n"; $header .= "Content-Type: text/html;"; $mail_body = ' Name: '.$_POST[name].' has sent his input. Address: '. $_POST[address] . '<br> Address2: '. $_POST[address2] . '<br> City: '. $_POST[city] . '<br> State: '. $_POST[state] . '<br> Zipcode: '. $_POST[zipcode] . '<br> Phone: '. $_POST[phone] . '<br> Email: '. $_POST[email] . '<br> Passenger_number: '. $_POST[passnumber] . '<br> Cabin_type: '. $_POST[cabin_type] . '<br> Cruise_1: '. $_POST[cruise_1] . '<br> Cruise_2: '. $_POST[cruise_2] . '<br> Comments: '. $_POST[comments] . '<br>' ; mail ($mailuser, 'San Juan Reservation Form', $mail_body, $header); echo 'Thank You for contacting us. We will be getting back with you shortly. '; } else { // *** The input text did not match the stored text, so they failed *** // *** You would probably not want to include the correct answer, but // unless someone is trying on purpose to circumvent you specifically, // its not a big deal. If someone is trying to circumvent you, then // you should probably use a more secure way besides storing the // info in a cookie that always has the same name! *** echo "Sorry, you did not pass the CAPTCHA test.<br><br>"; echo "You said " . $_POST["captcha_input"]; echo " while the correct answer was " . $_SESSION["pass"]; echo " - Please click back in your browser and try again <br><br>"; } ?> Here is the changes to the captcha.php file I did <? if ($_SERVER["REQUEST_METHOD"] <> "POST") die("You can only reach this page by posting from the html form"); // *** The text input will come in through the variable $_POST["captcha_input"], // while the correct answer is stored in the cookie $_COOKIE["pass"] *** if ($_POST["security"] == $_SESSION["pass"]) { // *** They passed the test! *** // *** This is where you would post a comment to your database, etc *** echo "Correct! You have passed the captcha test. <br><br>"; echo "You information input has been sent <br><br>"; echo "This is what you sent <br><br>"; echo "Name: \"" . $_POST["name"] . "\" <br>"; echo "Address: \"" . $_POST["address"] . "\" <br>"; echo "Address2: \"" . $_POST["address2"] . "\" <br>"; echo "City: \"" . $_POST["city"] . "\" <br>"; echo "State: \"" . $_POST["state"] . "\" <br>"; echo "Zipcode: \"" . $_POST["zipcode"] . "\" <br>"; echo "Phone: \"" . $_POST["phone"] . "\" <br>"; echo "Email: \"" . $_POST["email"] . "\" <br>"; echo "Passenger_Number: \"" . $_POST["passnumber"] . "\" <br>"; echo "Cabin_type: \"" . $_POST["cabin_type"] . "\" <br>"; echo "Cruise_1: \"" . $_POST["cruise_1"] . "\" <br>"; echo "Cruise_2: \"" . $_POST["cruise_2"] . "\" <br>"; echo "comments: \"" . $_POST["comments"] . "\" <br>"; //sends email via php to the following address $mailuser = "form.one@sanjuanislandcruises.com"; //echo 'default chosen address: '.$mailuser; $header = "Return-Path: ".$mailuser."\r\n"; $header .= "From: San Juan Reservations <".$mailuser.">\r\n"; $header .= "Content-Type: text/html;\r\n"; $mail_body .= '<html><body>'; $mail_body .= '<table rules="all" style="border-color: #670;" cellpadding="10">'; $mail_body .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) . "</td></tr>"; $mail_body .= "<tr><td><strong>Address:</strong> </td><td>" . strip_tags($_POST['address']) . "</td></tr>"; $mail_body .= "<tr><td><strong>Address2:</strong> </td><td>" . strip_tags($_POST['address2']) . "</td></tr>"; $mail_body .= "<tr><td><strong>City:</strong> </td><td>" . strip_tags($_POST['city']) . "</td></tr>"; $mail_body .= "<tr><td><strong>State:</strong> </td><td>" . strip_tags($_POST['state']) . "</td></tr>"; $mail_body .= "<tr><td><strong>Zipcode:</strong> </td><td>" . strip_tags($_POST['zipcode']) . "</td></tr>"; $mail_body .= "<tr><td><strong>Phone Number:</strong> </td><td>" . strip_tags($_POST['phone']) . "</td></tr>"; $mail_body .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>"; $mail_body .= "<tr><td><strong>Number of Passengers:</strong> </td><td>" . strip_tags($_POST['passnumber']) . "</td></tr>"; $mail_body .= "<tr><td><strong>Cabin Type:</strong> </td><td>" . strip_tags($_POST['cabin_type']) . "</td></tr>"; $mail_body .= "<tr><td><strong>Cruise Option 1:</strong> </td><td>" . strip_tags($_POST['cruise_1']) . "</td></tr>"; $mail_body .= "<tr><td><strong>Cruise Option 2:</strong> </td><td>" . strip_tags($_POST['cruise_2']) . "</td></tr>"; $mail_body .= "<tr><td><strong>Customer Comments:</strong> </td><td>" . strip_tags($_POST['comments']) . "</td></tr>"; $mail_body .= "</table>"; $mail_body .= "</body></html>"; mail ($mailuser, 'San Juan Reservation Form', $mail_body, $header); echo 'Thank You for contacting us. We will be getting back with you shortly. '; } else { // *** The input text did not match the stored text, so they failed *** // *** You would probably not want to include the correct answer, but // unless someone is trying on purpose to circumvent you specifically, // its not a big deal. If someone is trying to circumvent you, then // you should probably use a more secure way besides storing the // info in a cookie that always has the same name! *** echo "Sorry, you did not pass the CAPTCHA test.<br><br>"; echo "You said " . $_POST["captcha_input"]; echo " while the correct answer was " . $_SESSION["pass"]; echo " - Please click back in your browser and try again <br><br>"; } ?> Any help would be appreciated. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/297005-php-form-email-help/ Share on other sites More sharing options...
iarp Posted June 25, 2015 Share Posted June 25, 2015 You most likely need to turn on display_errors within php.ini to see what message you are getting, or check the server logs. Quote Link to comment https://forums.phpfreaks.com/topic/297005-php-form-email-help/#findComment-1514909 Share on other sites More sharing options...
CroNiX Posted June 25, 2015 Share Posted June 25, 2015 You don't seem to have a session_start() at the top of your page, but you are using $_SESSION. Another thing I see is you don't define $mail_body before you start appending to it using the .= concatenation. That's probably not breaking things but it probably is issuing a 'notice' level error. $mail_body .= '<html><body>'; Try $mail_body = '<html><body>'; Your last $header should have \r\n at the end $header .= "Content-Type: text/html;\r\n"; In addition to turning display errors on and checking the logs, I'd also try outputting your $mail_body HTML to the page and not sending the email to see if your table is displaying correctly as a quick test. Quote Link to comment https://forums.phpfreaks.com/topic/297005-php-form-email-help/#findComment-1514927 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.