Jump to content

Help in sending a PHP email?


Mr Chris

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<[email protected]>\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";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.