Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/167021-help-in-sending-a-php-email/
Share on other sites

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";
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.