HanneSThEGreaT Posted October 8, 2011 Share Posted October 8, 2011 Hello again. I have a site where people can order items, as per this thread : http://www.phpfreaks.com/forums/index.php?topic=345342.0 Now, I would like to be able to send an order confirmation to the person that has made the order, as well as to the site's ordering department. I have this code : <?php if(isset($_POST['Email'])) { $email_to = "[email protected]"; $email_subject = "The New Me - Order Confirmation"; function died($error) { // error code echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['FName']) || !isset($_POST['LName']) || !isset($_POST['Email']) || !isset($_POST['Phone']) || !isset($_POST['Address']) || !isset($_POST['City']) || !isset($_POST['Pcode'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['FName']; // required $last_name = $_POST['LName']; // required $email_from = $_POST['Email']; // required $telephone = $_POST['Phone']; // not required $address = $_POST['Address']; // required $city = $_POST['City']; // required $postal_code = $_POST['Pcode']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "The New Me - Single Order details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Address: ".clean_string($address)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "Postal Code: ".clean_string($postal_code)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> Thank you for contacting us. We will be in touch with you very soon. <?php } ?> This is the whole page's code : <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>The New Me</title> <meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1" /> <meta http-equiv="imagetoolbar" content="no" /> <meta name="description" content="An Example of the a flexible, scalable background image." /> <meta name="author" content="Michael Bester" /> <link rel="stylesheet" href="css/flexi-background.css" type="text/css" media="screen" /> <style type="text/css" media="screen"> h1 { background-color: #fff; background-color: rgba(255,255,255,0.; color: #333; font-family: Helvetica, Arial, sans-serif; font-size: 2em; font-weight: normal; margin-top: 2.5%; margin-bottom: 1em; padding: 0.5em 0; position: absolute; text-align: center; width: 100%; z-index: 2; } h2 { background-color: #fff; background-color: rgba(255,255,255,0.; color: #333; font-family: Helvetica, Arial, sans-serif; font-size: 1em; z-index: 2; text-align: center; } p { background-color: #fff; background-color: rgba(255,255,255,0.; color: #333; font-family: Helvetica, Arial, sans-serif; font-weight: normal; z-index: 2; } .copyright { background-color: #fff; background-color: rgba(255,255,255,0.; color: #333; font-family: Helvetica, Arial, sans-serif; font-weight: normal; font-size: 10px; z-index: 2; } </style> </head> <body> <h1>Welcome to the New Me</h1> <script src="js/flexi-background.js" type="text/javascript" charset="utf-8"></script> <table border="0" cols="3" width="100%"> <tr align="center"> <td><a href="index.htm"><img src="images/Home.gif" alt="Home" id="home" border="0"></a></td><td><a href="products.php"><img src="images/Products.gif" alt="Products" id="prod" border="0"></a></td><td><a href="contact_us.htm"><img src="images/Contact_us.gif" alt="Contact Us" id="contact" border="0"></a></td><td><a href="questions.htm"><img src="images/Questions.gif" alt="Questions?" id="Questions" border="0"></a></td> </tr> </table> <p> </p> <table cols="3" width="100%"> <tr><td width="25%"> </td><td width="50%"><h2>Have you always wanted to lose weight naturally and keep it off?</h2></td><td width="25%"> </td></tr> <tr><td valign="top" align="center"> <img border="0" src="images/gesonde%20kos.jpg" width="129" height="62"><p> <img border="0" src="images/Green%20Tea%201.jpg" width="127" height="92"></p> <p><img border="0" src="images/Picture1.png" width="113" height="265"></td><td><p> <?php if(isset($_POST['Email'])) { $email_to = "[email protected]"; $email_subject = "The New Me - Order Confirmation"; function died($error) { // error code echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['FName']) || !isset($_POST['LName']) || !isset($_POST['Email']) || !isset($_POST['Phone']) || !isset($_POST['Address']) || !isset($_POST['City']) || !isset($_POST['Pcode'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['FName']; // required $last_name = $_POST['LName']; // required $email_from = $_POST['Email']; // required $telephone = $_POST['Phone']; // not required $address = $_POST['Address']; // required $city = $_POST['City']; // required $postal_code = $_POST['Pcode']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "The New Me - Single Order details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Address: ".clean_string($address)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "Postal Code: ".clean_string($postal_code)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> Thank you for contacting us. We will be in touch with you very soon. <?php } ?> </p></td> <td valign="top" align="left"> <img border="0" src="images/Picture2.png" width="117" height="129"><p> <img border="0" src="images/Picture3.png" width="171" height="91"></p> <p><img border="0" src="images/skaal.jpg" width="111" height="111"></td></tr> <tr><td valign="top" align="center"> </td><td> </td> <td valign="top" align="left"> </td></tr> <tr><td valign="top" align="center"> </td><td> </td> <td valign="top" align="left"> </td></tr> <tr><td valign="top" align="center"> </td><td> <img border="0" src="images/suurlemoen%20sap.jpg" width="124" height="119" align="left"><img border="0" src="images/water.jpg" width="120" height="120" align="right"></td> <td valign="top" align="left"> </td></tr> </table> <p class="copyright"><a href = "http://www.ncc-cla.com">© NCC - vereeniging 2011</a></p> </body> </html> I know I'm probably doing something wrong, can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/ Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 OK, I have now tried something else : <?php error_reporting(E_ALL); ini_set('display_errors',1); $to = "[email protected]"; $subject = "The New Me - Order Confirmation"; $headers = "From: $email\n"; $first_name = $_POST['FName']; // required $last_name = $_POST['LName']; // required $telephone = $_POST['Phone']; // not required $address = $_POST['Address']; // required $city = $_POST['City']; // required $postal_code = $_POST['Pcode']; // required $email = $_POST["Email"]; $email_message = "The New Me - Order Confirmation below.\n $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Address: ".clean_string($address)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "Postal Code: ".clean_string($postal_code)."\n"; $user = "$email"; $usersubject = "The New Me - Thank You"; $userheaders = "From: [email protected]\n"; $usermessage = "Thank you for your order at The New Me."; mail($to,$subject,$message,$headers); mail($user,$usersubject,$usermessage,$userheaders); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>The New Me</title> <meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1" /> <meta http-equiv="imagetoolbar" content="no" /> <meta name="description" content="An Example of the a flexible, scalable background image." /> <meta name="author" content="Michael Bester" /> <link rel="stylesheet" href="css/flexi-background.css" type="text/css" media="screen" /> <style type="text/css" media="screen"> h1 { color: #black; font-family: Helvetica, Arial, sans-serif; font-size: 2em; font-weight: normal; margin-top: 2.5%; margin-bottom: 1em; padding: 0.5em 0; position: absolute; text-align: center; width: 100%; z-index: 2; } h2 { color: #black; font-family: Helvetica, Arial, sans-serif; font-size: 1em; z-index: 2; text-align: center; } p { color: #black; font-family: Helvetica, Arial, sans-serif; font-weight: normal; z-index: 2; } .copyright { color: #black; font-family: Helvetica, Arial, sans-serif; font-weight: normal; font-size: 10px; z-index: 2; } </style> </head> <body> <h1>Thank you for your Order!</h1> <script src="js/flexi-background.js" type="text/javascript" charset="utf-8"></script> <table border="0" cols="3" width="100%"> <tr align="center"> <td><a href="index.htm"><img src="images/Home.gif" alt="Home" id="home" border="0"></a></td><td><a href="products.php"><img src="images/Products.gif" alt="Products" id="prod" border="0"></a></td><td><a href="contact_us.htm"><img src="images/Contact_us.gif" alt="Contact Us" id="contact" border="0"></a></td><td><a href="questions.htm"><img src="images/Questions.gif" alt="Questions?" id="Questions" border="0"></a></td> </tr> </table> <p> </p> <table cols="3" width="100%"> <tr><td width="25%"> </td><td width="50%"><h2>Order Completed!</h2></td><td width="25%"> </td></tr> <tr><td valign="top" align="center"> <img border="0" src="images/gesonde%20kos.jpg" width="129" height="62"><p> <img border="0" src="images/Green%20Tea%201.jpg" width="127" height="92"></p> <p><img border="0" src="images/Picture1.png" width="113" height="265"></td><td><p> </p></td> <td valign="top" align="left"> <img border="0" src="images/Picture2.png" width="117" height="129"><p> <img border="0" src="images/Picture3.png" width="171" height="91"></p> <p><img border="0" src="images/skaal.jpg" width="111" height="111"></td></tr> <tr><td valign="top" align="center"> </td><td> </td> <td valign="top" align="left"> </td></tr> <tr><td valign="top" align="center"> </td><td> </td> <td valign="top" align="left"> </td></tr> <tr><td valign="top" align="center"> </td><td> <img border="0" src="images/suurlemoen%20sap.jpg" width="124" height="119" align="left"><img border="0" src="images/water.jpg" width="120" height="120" align="right"></td> <td valign="top" align="left"> </td></tr> </table> <p class="copyright"><a href = "http://www.ncc-cla.com">© NCC - vereeniging 2011</a></p> </body> </html> I have tried this a million times and no message come through. As soon as I can get an email confirmation, I can try to implement a summary of all products in there as well. Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277650 Share on other sites More sharing options...
titan21 Posted October 10, 2011 Share Posted October 10, 2011 In your second post - I couldn't see where $message was being set. I this perhaps the issue? Can you check your logs? Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277654 Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 Hello! Thank you for your quick reply. OK, I did fix all the syntax errors, it looks like this now : <?php $to = "[email protected]"; $subject = "The New Me - Order Confirmation"; $headers = "From: $email\n"; $first_name = $_POST['FName']; // required $last_name = $_POST['LName']; // required $telephone = $_POST['Phone']; // not required $address = $_POST['Address']; // required $city = $_POST['City']; // required $postal_code = $_POST['Pcode']; // required $email = $_POST["Email"]; $email_message = "The New Me - Order Confirmation below.\n $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Address: ".clean_string($address)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "Postal Code: ".clean_string($postal_code)."\n"; $user = $email; $usersubject = "The New Me - Thank You"; $userheaders = "From: [email protected]\n"; $usermessage = "Thank you for your order at The New Me."; mail($to,$subject,$email_message,$headers); mail($user,$usersubject,$usermessage,$userheaders); ?> Still I get nothing. How do I get the log that you've mentioned? Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277661 Share on other sites More sharing options...
titan21 Posted October 10, 2011 Share Posted October 10, 2011 Um - okay - first of all let's check that your host is allowing the mail functionality(I think this can be switched off) - create a new file and run a very simple mail command: mail("[email protected]", "This is a test", "It's working") See if that works. Also - it might be worth outputting your variables to make sure they are set correctly. With regards to your log - if you're not running your own host - i'm not really sure where you can get access to this. Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277662 Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 OK, I did get the test message, so that side seems to be in order. I am now attempting : <?php $to = "[email protected]" ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = "Web Contact Data"; $fields = array(); $fields{"FName"} = "Name"; $fields{"City"} = "City"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: " . $from; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com"; if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a name, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); } } ?> But it tells me I haven't entered an email eventhough I have... I do not know what to do anymore Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277671 Share on other sites More sharing options...
titan21 Posted October 10, 2011 Share Posted October 10, 2011 Okay - try: print_r($_REQUEST) to make sure your variables are set. Also - are these variables being passed by GET or PAT methods - try using $_GET or $_POST if they are. I'm not sure what the value of $_REQUEST is to be honest. Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277673 Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 Hello again, thank for your guidance. All that shows was : Array( ) Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277676 Share on other sites More sharing options...
titan21 Posted October 10, 2011 Share Posted October 10, 2011 So looks like they are not being passed along - what HTML are u using to send the form variables? Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277677 Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 Hello again. This is my order form : <FORM Name="TNMOrder" Id = "TNMOrder" Method = "Post" Action="orderform.php" EncType = "Text/Plain"> <table border="0" width="100%"> <tr> <td align="right" width="25%">First Name</td> <td align="left" width="50%"><input type="text" name="FName" size="50"></td> <td width="25%" rowspan="14" valign="top"> <img border="0" src="images/Picture2.png" width="117" height="129"><p> <img border="0" src="images/Picture3.png" width="171" height="91"></p> <p><img border="0" src="images/skaal.jpg" width="111" height="111"></p> <p> <img border="0" src="images/gesonde%20kos.jpg" width="129" height="62"></p> <p> </td> </tr> <tr> <td align="right">Last Name</td> <td align="left"><input type="text" name="LName" size="50"></td> </tr> <tr> <td align="right">Email</td> <td align="left"><input type="text" name="Email" id="Email"size="50"></td> </tr> <tr> <td align="right">Phone</td> <td align="left"><input type="text" name="Phone" size="50"></td> </tr> <tr> <td align="right">Address</td> <td align="left"><textarea rows="3" name="Address" cols="40"></textarea></td> </tr> <tr> <td align="right">City</td> <td align="left"><input type="text" name="City" size="50"></td> </tr> <tr> <td align="right">Postal Code</td> <td align="left"><input type="text" name="Pcode" size="50"></td> </tr> <tr> <td align="right">Order Details</td> <td align="center"><div class="orderdet"> <?php //top of the page //error_reporting(E_ALL); //ini_set('display_errors',1); // This makes sure somebody actually selected a product if (isset($_POST['ordered'])) { // We can assign $_POST['product'] to a variable to make it easier to type out $prod = $_POST['product']; // Throw a little intro to see how many they checked echo 'You selected ' , count($_POST['ordered']) , ' products.'; // Now we loop through it and get the IDS that were selected // Foreach lets you select the $key and the $value for each iteration of the loop // foreach ($_POST['ordered'] as $key=>$id) { echo '<p/> ProdName: ' , $prod[$id]['name'] , '<br/> ProdPrice: ' , $prod[$id]['price'] , '<br/> ProdQty: ' , $prod[$id]['qty'] , ' <hr/>'; $TOT += $prod[$id]['price'] * $prod[$id]['qty']; } $TOT2 = $TOT + 55; } ?> <script type="text/javascript"> function AddUTI() { var TOT = parseInt(document.TNMOrder.HIDDENTOT.value); document.TNMOrder.TOTAL.value = TOT; } function AddCollect() { var TOT2 = parseInt(document.TNMOrder.HIDDENTOT2.value); document.TNMOrder.TOTAL.value = TOT2; } function AddDeliver() { var TOT3 = parseInt(document.TNMOrder.HIDDENTOT2.value); document.TNMOrder.TOTAL.value = TOT3; } </script> </div> </td></tr> <tr> <td align="right">Delivery Method<input type="hidden" name="HIDDENTOT" value=<?=$TOT2?>><input type="hidden" name="HIDDENTOT2" value=<?=$TOT?>></td> <td><p class="Delivery"><input type="radio" value="Collect" name="Delivery" id="Delivery" onclick="AddCollect();">Collect at <a href="http://www.ncc-cla.com/contact_us.htm">NCC Offices</a><br> <input type="radio" value="Deliver" name="Delivery" id="Delivery" onclick="AddDeliver();">Deliver<br> <input type="radio" value="UTI" name="Delivery" id="Delivery" onclick="AddUTI();">Courier via UTI - This will infer a Courier Charge of R55</p> </td></tr> <td align="right">Total</td> <td align="center"><INPUT TYPE=TEXT NAME="TOTAL" SIZE="10" value=<?=$TOT?>> <input type="submit" value="Submit" name="Submit"> <input type="reset" value="Reset" name="Reset"></td> </tr></table></form> Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277680 Share on other sites More sharing options...
titan21 Posted October 10, 2011 Share Posted October 10, 2011 Try changing your $_REQUEST to $_GET and then do a print_r($_GET) to see what u get. Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277681 Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 Still the same results. I do not understand why the info doesn't get passed through Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277683 Share on other sites More sharing options...
titan21 Posted October 10, 2011 Share Posted October 10, 2011 Sorry just spotted this in your form: Method = "Post" Try print_r($_POST) Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277687 Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 Same results Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277691 Share on other sites More sharing options...
titan21 Posted October 10, 2011 Share Posted October 10, 2011 Just wanna check that your putting print_r($_POST) at the top of orderform.php and not in the code below the form? Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277694 Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 Thanks so much for your patience. Yes, I have put it on top of orderform.php and it still didn't give me anything. I managed to do this : 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 = "The New Me - Order"; $message .= "<html><body>"; $message .= "<b>Hey! How are you today?</b>"; $message .= "<br>Regards"; $message .= "</body></html>"; send_email("[email protected]", "[email protected]", $subject , $message); BUT, if I cannot get the Posted data pulled, this will not work because I cannot get the sender's email address. I'll try again. Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277701 Share on other sites More sharing options...
Buddski Posted October 10, 2011 Share Posted October 10, 2011 Your original code, and the ones preceding it did not close the initial $message/$email_message strings. $email_message = "The New Me - Order Confirmation below.\n $email_message .= "First Name: ".clean_string($first_name)."\n"; As you can see it isnt closing.. Should have been $email_message = "The New Me - Order Confirmation below.\n"; $email_message .= "First Name: ".clean_string($first_name)."\n"; Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277704 Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 Hello again. I went back to my old code, and made 100% sure each line gets closed properly. I did this : if(isset($_POST['Email'])) { $email_to = "[email protected]"; $email_subject = "The New Me - Order Confirmation"; function died($error) { // error code echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['FName']) || !isset($_POST['LName']) || !isset($_POST['Email']) || !isset($_POST['Phone']) || !isset($_POST['Address']) || !isset($_POST['City']) || !isset($_POST['Pcode'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['FName']; // required $last_name = $_POST['LName']; // required $email_from = $_POST['Email']; // required $telephone = $_POST['Phone']; // not required $address = $_POST['Address']; // required $city = $_POST['City']; // required $postal_code = $_POST['Pcode']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "The New Me - Order details.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Address: ".clean_string($address)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "Postal Code: ".clean_string($postal_code)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n"; 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); echo "Thank you for contacting us. We will be in touch with you very soon."; } Now I get just an empty page Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277710 Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 OK, I included an else condition ( because I test for isset initially ) When I do this : if(isset($_POST['Email'])) { $email_to = "[email protected]"; $email_subject = "The New Me - Order Confirmation"; function died($error) { // error code echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['FName']) || !isset($_POST['LName']) || !isset($_POST['Email']) || !isset($_POST['Phone']) || !isset($_POST['Address']) || !isset($_POST['City']) || !isset($_POST['Pcode'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['FName']; // required $last_name = $_POST['LName']; // required $email_from = $_POST['Email']; // required $telephone = $_POST['Phone']; // not required $address = $_POST['Address']; // required $city = $_POST['City']; // required $postal_code = $_POST['Pcode']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "The New Me - Order details.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Address: ".clean_string($address)."\n"; $email_message .= "City: ".clean_string($city)."\n"; $email_message .= "Postal Code: ".clean_string($postal_code)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n"; 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); echo "Thank you for contacting us. We will be in touch with you very soon."; } else { echo "not pulled"; } It shows the not pulled message. So, the problem seems to be that the info doesn't get Posted properly from the order.php form Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277711 Share on other sites More sharing options...
Buddski Posted October 10, 2011 Share Posted October 10, 2011 Do you have your error_reporting enabled? error_reporting(E_ALL); ini_set('display_errors',1); And ensure that $_POST is actually sent. Post your form. Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277712 Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 Yes, I have - probably put the error reporting at the wrong place. My form looks like this : <FORM Name="TNMOrder" Id = "TNMOrder" Method = "Post" Action="orderform.php" EncType = "Text/Plain"> <table border="0" width="100%"> <tr> <td align="right" width="25%">First Name</td> <td align="left" width="50%"><input type="text" name="FName" size="50"></td> <td width="25%" rowspan="14" valign="top"> <img border="0" src="images/Picture2.png" width="117" height="129"><p> <img border="0" src="images/Picture3.png" width="171" height="91"></p> <p><img border="0" src="images/skaal.jpg" width="111" height="111"></p> <p> <img border="0" src="images/gesonde%20kos.jpg" width="129" height="62"></p> <p> </td> </tr> <tr> <td align="right">Last Name</td> <td align="left"><input type="text" name="LName" size="50"></td> </tr> <tr> <td align="right">Email</td> <td align="left"><input type="text" name="Email" id="Email"size="50"></td> </tr> <tr> <td align="right">Phone</td> <td align="left"><input type="text" name="Phone" size="50"></td> </tr> <tr> <td align="right">Address</td> <td align="left"><textarea rows="3" name="Address" cols="40"></textarea></td> </tr> <tr> <td align="right">City</td> <td align="left"><input type="text" name="City" size="50"></td> </tr> <tr> <td align="right">Postal Code</td> <td align="left"><input type="text" name="Pcode" size="50"></td> </tr> <tr> <td align="right">Order Details</td> <td align="center"><div class="orderdet"> <?php session_start(); // This makes sure somebody actually selected a product if (isset($_POST['ordered'])) { // We can assign $_POST['product'] to a variable to make it easier to type out $prod = $_POST['product']; // Throw a little intro to see how many they checked echo 'You selected ' , count($_POST['ordered']) , ' products.'; // Now we loop through it and get the IDS that were selected // Foreach lets you select the $key and the $value for each iteration of the loop // foreach ($_POST['ordered'] as $key=>$id) { echo '<p/> ProdName: ' , $prod[$id]['name'] , '<br/> ProdPrice: ' , $prod[$id]['price'] , '<br/> ProdQty: ' , $prod[$id]['qty'] , ' <hr/>'; $TOT += $prod[$id]['price'] * $prod[$id]['qty']; } $TOT2 = $TOT + 55; } ?> <script type="text/javascript"> function AddUTI() { var TOT = parseInt(document.TNMOrder.HIDDENTOT.value); document.TNMOrder.TOTAL.value = TOT; } function AddCollect() { var TOT2 = parseInt(document.TNMOrder.HIDDENTOT2.value); document.TNMOrder.TOTAL.value = TOT2; } function AddDeliver() { var TOT3 = parseInt(document.TNMOrder.HIDDENTOT2.value); document.TNMOrder.TOTAL.value = TOT3; } </script> </div> </td></tr> <tr> <td align="right">Delivery Method<input type="hidden" name="HIDDENTOT" value=<?=$TOT2?>><input type="hidden" name="HIDDENTOT2" value=<?=$TOT?>></td> <td><p class="Delivery"><input type="radio" value="Collect" name="Delivery" id="Delivery" onclick="AddCollect();">Collect at <a href="http://www.ncc-cla.com/contact_us.htm">NCC Offices</a><br> <input type="radio" value="Deliver" name="Delivery" id="Delivery" onclick="AddDeliver();">Deliver<br> <input type="radio" value="UTI" name="Delivery" id="Delivery" onclick="AddUTI();">Courier via UTI - This will infer a Courier Charge of R55</p> </td></tr> <td align="right">Total</td> <td align="center"><INPUT TYPE=TEXT NAME="TOTAL" SIZE="10" value=<?=$TOT?>> <input type="submit" value="Submit" name="Submit"> <input type="reset" value="Reset" name="Reset"></td> </tr> <tr> <td align="right"> </td> <td align="center"> <img border="0" src="images/suurlemoen%20sap.jpg" width="124" height="119" align="right"> <img border="0" src="images/water.jpg" width="120" height="120" align="left"></td> </tr> </table> </form> I am attaching both order.php and orderform.php here [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277714 Share on other sites More sharing options...
Buddski Posted October 10, 2011 Share Posted October 10, 2011 Remove the enctype attribute. Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277715 Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 WOW!!!!!!!! That did it!! I repeat you guys are geniuses!! I knew it had to be something small!!! Thanks!! Last question ( for now obviously ) How can I get the products that were ordered also included in that email? Should I make use of a session? Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277718 Share on other sites More sharing options...
Buddski Posted October 10, 2011 Share Posted October 10, 2011 You can post the generated string to the second page in a hidden field or just send through all the ordered products again and iterate through like you have on the form page.. Sending a pre-formatted string will be probably quicker for you. Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277722 Share on other sites More sharing options...
HanneSThEGreaT Posted October 10, 2011 Author Share Posted October 10, 2011 Thanx. I did try this on order.php : if (isset($_POST['ordered'])) { // We can assign $_POST['product'] to a variable to make it easier to type out $prod = $_POST['product']; // Throw a little intro to see how many they checked echo 'You selected ' , count($_POST['ordered']) , ' products.'; // Now we loop through it and get the IDS that were selected // Foreach lets you select the $key and the $value for each iteration of the loop // foreach ($_POST['ordered'] as $key=>$id) { echo '<p/> ProdName: ' , $prod[$id]['name'] , '<br/> ProdPrice: ' , $prod[$id]['price'] , '<br/> ProdQty: ' , $prod[$id]['qty'] , ' <hr/>'; echo <input type="hidden" value = $prod[$id]['name']>; echo <input type="hidden" value = $prod[$id]['price']>; echo <input type="hidden" value = $prod[$id]['qty']>; $TOT += $prod[$id]['price'] * $prod[$id]['qty']; } $TOT2 = $TOT + 55; echo <input type="hidden" value = $TOT>; echo <input type="hidden" value = $TOT2>; } It didn't bring them through. Am I formulating the hidden fields wrong? Quote Link to comment https://forums.phpfreaks.com/topic/248679-email-order-confirmation/#findComment-1277731 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.