Home › Forums › Back End › [Solved] Need Help with PHP code for using an array checkbox › Re: [Solved] Need Help with PHP code for using an array checkbox
Thank you holyhttp. Unfortunately, that code also returned "Array" on my email.
The friend who was helping me with the original PHP code was able to write the "foreach" code into the PHP. It is now working and displaying correctly when it’s returned via email.
Here is the corrected code that works for my site:
“;
$firstname = $HTTP_POST_VARS[‘first_name’];
$lastname = $HTTP_POST_VARS[‘last_name’];
$email = $HTTP_POST_VARS[’email_address’];
$phone = $HTTP_POST_VARS[‘phone_number’];
$contact = $HTTP_POST_VARS[‘contact’];
$times = $HTTP_POST_VARS[‘times’];
$room = $HTTP_POST_VARS[‘room’];
$otherroom = $HTTP_POST_VARS[‘other_room’];
$project = $HTTP_POST_VARS[‘project’];
$squarefootage = $HTTP_POST_VARS[‘square_footage’];
$timing = $HTTP_POST_VARS[‘timing’];
$anythingelse = $_POST[‘anything_else’];
$headers = “From: $emailn”;
$headers . “MIME-Version: 1.0n”
. “Content-Transfer-Encoding: 7bitn”
. “Content-type: text/html; charset = “iso-8859-1″;nn”;
// Build the email body text
$emailcontent = ”
—————————————————————————–
$subject
—————————————————————————–
Customer’s Name: $firstname $lastname
Customer’s Email Address: $email
Customer’s Phone Number: $phone
Customer prefers to be contacted via: $contact
Best time to call the Customer: $times
Room(s) that the project is for: “;
foreach($room as $value) { $emailcontent .= “$value, “; }
$emailcontent .= ”
Room not in the list: $otherroom
Is this project new construction, a remodel, or a room update? “;
foreach($project as $value) { $emailcontent .= “$value, “; }
$emailcontent .= ”
Approximate square footage of the project: $squarefootage
When the project will start: $timing
Is there anything else we should know about your project? $anythingelse
“;
// Check that the email address entered matches the standard email address format
if (!eregi(“^[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,6}$”, $email)) {
echo “
It appears you entered an invalid email address
“;
}
elseif (!trim($firstname)) {
echo “
Please go back and enter your First Name
“;
}
elseif (!trim($lastname)) {
echo “
Please go back and enter your Last Name
“;
}
elseif (!trim($email)) {
echo “
Please go back and enter your Email Address
“;
}
elseif (!trim($phone)) {
echo “
Please go back and enter your Phone Number
“;
}
// Sends out the email or will output the error message
elseif (mail($sendto, $subject, $emailcontent, $headers)) {
header( “Location: $successurl” );
exit ;
}
}
else {
header( “Location: $successurl” );
exit ;
}
?>