I’m very new to php (and programming in general) and have been trying to get
this form to pass multiple checkbox results to an email address. The rest of
the form is working perfectly except the checkboxes. I’ve been going round in
circles for over a week now, so any help would be greatly appreciated.
<?php
if ($_POST) {
if (get_magic_quotes_gpc()) {
foreach ($_POST as $key => $value) {
$temp = stripslashes($value);
$_POST[$key] = $temp;
}
}
$to = ‘mail@domain.com’;
$subject = ‘Feedback from website’;
// message
$message = "Event Type: " . $_POST[‘eventtype’] . "
";
$message .= "Event Date: " . $_POST[‘eventdate’] . "
";
$message .= "No of guests: " . $_POST[‘noofguests’] . "
";
$message .= "Desired Location: " . $_POST[‘desiredlocation’] . "
";
foreach($_POST[‘check’] as $value)
{
$check_msg .= “Checked: $value”. "
";
}
// with this it passes the name array to the email
// $message .= "Service you require: " . $_POST[‘check’] . "
";
$message .= "First Name: " . $_POST[‘reqfirstname’] . "
";
$message .= "Surname: " . $_POST[‘reqsurname’] . "
";
$message .= "Telephone: " . $_POST[‘reqphonenumber’] . "
";
$message .= "Email: " . $_POST[‘reqemail’] . "
";
$message .= "Address1: " . $_POST[‘reqaddress1’] . "
";
$message .= "Address2: " . $_POST[‘reqaddress2’] . "
";
$message .= "Postcode: " . $_POST[‘reqpostcode’] . "
";
$message .= "Country: " . $_POST[‘reqcountry’] . "
";
$message .= "Contact us by: " . $_POST[‘contactusby’] . "
";
$message .= "Convenient Time: " . $_POST[‘convenienttime’] . "
";
$message .= "How did you find us?: " . $_POST[‘findus’] . "
";
$message .= "Message: " . $_POST[‘message’] . "
";
// headers
$headers = "From: feedback@domain.com
";
$headers .= "Reply-To: " . $_POST[‘email’] . "
";
$headers .= "Cc: email@domain.com
";
$headers .= “Content-type: text/plain; charset=UTF-8”;
$sent = mail($to, $subject, $message, $headers, $check_msg);
}
?>
And the form…
<form action="<?php echo $_SERVER[‘PHP_SELF’]; ?>" method=“post” id=“apply” name=“apply” onSubmit=“return checkrequired(this)”>
<dl>
<input name=“check[]” type=“checkbox” value=“service1” title=“service1” >
Service1
</dd>
<dd>
<input type=“checkbox” name=“check[]” value=“service2” title=“service2” >
Service2</dd>
<dd>
<input name=“check[]” type=“checkbox” title=“service3” value=“service3” >
Service3</dd>
<dd>
</dl>
</form>