HTML/PHP EMAIL FORM - FOREACH & VARIABLE VARIABLES
Posted: Sat Mar 26, 2011 11:28 pm
Hello there,
I am an intermediate PHP developer and am new to this forum. I have picked my brain for three hours on this code and still cant figure it out.
Basically, what I want this code to do is to send an email via PHP. The problem I am having is with the foreach statement and the $message5 variable in the email.
You will notice that I have a foreach statement that returns $FIELDTITLE and $VALUE into the $message5 variable... However, everytime I run the foreach statement, it obviously resets the $fieldtitle and $value to the very last submission sent through the FOREACH statement.
Basically, I want to display EVERYTHING that runs through the FOREACH STATEMENT... not just the last submission. I don't know how to display them all and still send it through the PHP mail $message5 variable. How this code works right now, it only displays the very last submission... I figure I need to incorporate a variable variable somehow so that everytime the foreach statement runs, it creates a new variable. And then $message5 can be the combination of all those variables....
Any input on how to get it t would be great!
I am an intermediate PHP developer and am new to this forum. I have picked my brain for three hours on this code and still cant figure it out.
Basically, what I want this code to do is to send an email via PHP. The problem I am having is with the foreach statement and the $message5 variable in the email.
You will notice that I have a foreach statement that returns $FIELDTITLE and $VALUE into the $message5 variable... However, everytime I run the foreach statement, it obviously resets the $fieldtitle and $value to the very last submission sent through the FOREACH statement.
Basically, I want to display EVERYTHING that runs through the FOREACH STATEMENT... not just the last submission. I don't know how to display them all and still send it through the PHP mail $message5 variable. How this code works right now, it only displays the very last submission... I figure I need to incorporate a variable variable somehow so that everytime the foreach statement runs, it creates a new variable. And then $message5 can be the combination of all those variables....
Any input on how to get it t would be great!
Code: Select all
<?php
$account_name=$_POST['account_name'];
$your_name=$_POST['your_name'];
$email=$_POST['email'];
$phone_number=$_POST['phone_number'];
$month=$_POST['month'];
$day=$_POST['day'];
$year=$_POST['year'];
$date_of_order=$_POST['date_of_order'];
$need_order_by = "$month/$day/$year";
$additional_comments=$_POST['additional_comments'];
$uc_your_name = str_replace('_', ' ', ucwords($your_name));
$uc_account_name = str_replace('_', ' ', ucwords($account_name));
$message1 = "<html><body bgcolor='#666666'>Below is an order from <strong>$uc_your_name</strong> for the <strong>$uc_account_name</strong> wholesale account.<br/><br/>";
$message2 = "<strong>Order Requested On:</strong> $date_of_order<br/>";
$message3 = "<strong>Need Order Delivered By:</strong> $need_order_by<br/><br/>";
$message4 = "<strong>Order Details Below:</strong><br/><br/>";
foreach(($_POST) as $fieldtitle => $value) {
if(!empty($value) && $fieldtitle != "account_name" && $fieldtitle != "your_name" && $fieldtitle != "email" && $fieldtitle != "phone_number" && $fieldtitle != "additional_comments" && $fieldtitle != "month" && $fieldtitle != "day" && $fieldtitle != "year" && $fieldtitle != "date_of_order") {
$fieldtitle = str_replace('_', ' ', ucwords($fieldtitle));
$message5 = "<blockquote><strong> " . $fieldtitle . ":</strong> " . $value . "<br/><br/></blockquote>";
}
}
$message6 = "<strong>Additional Comments:</strong> $additional_comments<br/></body></html>";
$to = "cknewton@ksu.edu";
$subject = "Wholesale Order From $account_name";
$from = "$email";
$headers = "From: $from\r\n"; $headers .= "Reply-To: $from\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to,$subject,"$message1 $message2 $message3 $message4 $message5 $message6", $headers);
?>