awesomejoe Posted February 7, 2010 Share Posted February 7, 2010 Hi, I'm a noob at php so please bear with me. I'm trying to make an order form for my website and have the information sent to my email, but it is not completely working. This is my code: <html><body> <?php $order = $_POST['order']; $quantity = $_POST['quantity']; $price = $_POST['price']; $donation = $_POST['Donation']; $totalprice = 0; [color=red] echo "You ordered: " . " "; for ($i = 0; $i < sizeof($order); $i++) { $price[$i] = $price[$i] * $quantity[$i]; echo $quantity[$i] . " ". $order[$i] . " : $" . $price[$i] . " "; $totalprice = $totalprice + $price[$i]; } $totalprice = $totalprice + $donation; echo " Your donation: $" . $donation . " "; echo "Your subtotal: $" . $totalprice . " "; echo "This information has been sent to your email address. "; echo "Thank you for ordering!"; [/color] $to = "--@---" ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = $_REQUEST['Subject'] ; $fields = array(); $fields{"Name"} = "Name"; $fields{"Email"} = "Email"; $fields{"Subject"} = "Subject"; $fields{"order"} = "Order"; $fields{"quantity"} = "Quantity"; $fields{"Donation"} = "Donation"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } if($from == '') { echo "<script language=\"JavaScript\">\n"; echo "alert('You have not entered an email, please go back and try again');\n"; echo "</script>"; } else { $send = mail($to, $subject, $body, $headers); if($send) { } {print "We encountered an error sending your mail, please notify ---@----"; } } ?> </body></html> The problem is that when I receive the email, the Order and Quantity fields just say "Array" instead of their actual values. I would like to send an email formatted the same way as the text I printed out (red text) so is this possible and if so, how can I do this? Any help would be greatly appreciated Quote Link to comment Share on other sites More sharing options...
gizmola Posted February 7, 2010 Share Posted February 7, 2010 Hello Joe, Please use [code=php:0]... [/code] Around your code snippets. It's easier to read that way. I editted your post to do this, which is something I won't do in the future, but seeing as this is your first post. I also took out your email addy's, don't think you want to include those, or specific urls or passwords in the future. This site is indexed heavily by google. Quote Link to comment Share on other sites More sharing options...
gizmola Posted February 7, 2010 Share Posted February 7, 2010 It's because you're trying to use the php block operator "{}" rather than the array operator "[]". Hence your array remains undefined. Try this as your array definition: $fields['Name'] = "Name"; $fields['Email'] = "Email"; $fields['Subject'] = "Subject"; $fields['order'] = "Order"; $fields['quantity'] = "Quantity"; $fields['Donation'] = "Donation"; Quote Link to comment 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.