I'll try to explain best I can, let me know if I'm not clear please.
I created an array
$arr_email = array();
then I have an if statement that does several things, everything works, but the focus is adding to the array $arr_email.
if($_POST['Submit_Auto'] || !$_POST['Email_Auto']){
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post"><table class="verify"><tr><td><h3 style="margin-bottom:5px;">Auto Insurance Form</h3></td></tr><tr><td style="margin:0;padding:0;font-size:smaller;font-style:italic;">Please verify your information</td></tr>';
foreach($_POST as $var => $value)
{
if(in_array($var, $arr_auto)){
echo '<tr>';
echo '<td class="output">'.$var . '</td><td><span class="userInput">' . $value . '</span></td>';
$arr_email[$var] .= $value;
}
echo '</tr>';
}
print_r($arr_email);
echo '<tr><td><input type="button" value="Go Back" onclick="history.go(-1);return true;"/></td><td><input type="submit" name="Email_Auto" value="Request Quote"/></td></tr></table></form>';
}
I have a page that displays the information from a form on the page before. This works fine. I added a submit button to accept this information and send it. The submit button is in a form that has the action $_SERVER['PHP_SELF'] the name of the submit button is Email_Auto. Now i have a following else/if statement where I try to access $arr_email because I use it to create the body of my email.
else if($_POST['Email_Auto']){
$to = "
[email protected]";
$headers = "From: Think!nsure Auto Insurance Form";
$subject = "Auto Insurance Quote Request";
$body = "The user submitted the following:\n\n";
foreach($arr_email as $var => $value){
if(in_array($var, $arr_auto)){
$body .= sprintf("%20s : %s\n",$var,$value);
}
}
if (mail($to, $subject, $body, $headers)) {
echo("<p>Message successfully sent!</p>".$body);
print_r($arr_email);
} else {
echo("<p>Message delivery failed...</p>".$body);
print_r($arr_email);
}
}
The print_r($arr_email); in the if statement shows me what I want and the others do not, so it seems that once I hit the Email_Auto submit it clears the array. I might have a very wrong idea of what's going on here.
I get the emails, but they only have the default body.
Please help and please forgive me if I'm a complete idiot.
I can post all the php if necessary but this is all the relevant php.
Thanks,
Hatdrawn