Mr Chris Posted July 22, 2009 Share Posted July 22, 2009 Hello, I have a webpage and I echo data to that webpage via $_POST values sent from the previous page, which I echo on the page using a for loop which works nicely. <?php //***************************************** //Get the POST data SUBMITTED via the previous page and print it //***************************************** if ($_POST['Submit']) { for ($i = 0; $i < count($_POST['amount']); $i++) { echo "{$_POST['item_name'][$i]}<br />"; echo "{$_POST['amount'][$i]}<br />"; echo "{$_POST['quantity'][$i]}<br />"; } } //***************************************** //If Submit Button ON THIS PAGE is hit send an email //***************************************** if ($_POST['Submit_two']) { $message = "Here are your details:\n\n"; //This bit is the problem bit - THESE values are now lost as Submit_2 has been pressed?? for ($i = 0; $i < count($_POST['amount']); $i++) { $message .= "{$_POST['item_name'][$i]}\n"; $message .= "{$_POST['amount'][$i]}\n"; $message .= "<p>{$_POST['quantity'][$i]}\n\n"; } /////////////////////////////////////////////////////// $message .= "Many Thanks"; $headers = "From: My Name<donotreply@sddddasdsaasd.com>\r\n"; mail($your_email, "This is the headline", $message, $headers); } ?> <form action="" method="post" name="form" id="form"> <button name="Submit_two" type="submit" value="Submit_two">Submit_two</button> </form> Now as you will see on this page I also want to send an email, but ONLY when the Submit_two buttton is hit on this page, and in that email I want to grab those $POST values that I echo initially sent from the first page and send them in an email, but when I press Submit_two to do this the initial values are lost? So is there any way I can somehow keep them in memory to send in my email? Quote Link to comment https://forums.phpfreaks.com/topic/167021-help-in-sending-a-php-email/ Share on other sites More sharing options...
ignace Posted July 22, 2009 Share Posted July 22, 2009 Store the information between submits: $_SESSION['_POST'] = array(); $_SESSION['_POST'] = array_merge($_SESSION['_POST'], $_POST); Quote Link to comment https://forums.phpfreaks.com/topic/167021-help-in-sending-a-php-email/#findComment-880637 Share on other sites More sharing options...
Mr Chris Posted July 22, 2009 Author Share Posted July 22, 2009 Thanks, that sounds ideal but how would I save all my data into a session with my for loop for amount, quantity and item_name: for ($i = 0; $i < count($_POST['amount']); $i++) { echo "{$_POST['item_name'][$i]}<br />"; echo "{$_POST['amount'][$i]}<br />"; echo "{$_POST['quantity'][$i]}<br />"; } and then output it for amount, quantity and item_name:? for ($i = 0; $i < count($_POST['amount']); $i++) { $message .= "{$_POST['item_name'][$i]}\n"; $message .= "{$_POST['amount'][$i]}\n"; $message .= "<p>{$_POST['quantity'][$i]}\n\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/167021-help-in-sending-a-php-email/#findComment-880643 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.