my problem is that my e-mail form has a check box and it does not matter if the box is checked or not, it always transmits the same value, all other fields work ok, its just the checkbox I'm having problems. I tried several suggestions from this forum without luck, I'm not sure what I'm doing wrong! I'm not too proficient in PHP.
<form method="post" action="contact-form-handler1.php">
<div class= "form">
<div class="input-group margin-bottom-sm">
<span class="input-group-addon">
<i class="fa fa-user fa-fw" style="color:grey"></i>
</span>
<input class="form-control" type="text" name="name" placeholder="Name"
required>
</div><br>
<div class="input-group margin-bottom-sm">
<span class="input-group-addon">
<i class="fa fa-envelope-o fa-fw" style="color:grey"></i>
</span>
<input class="form-control" type="text" name="email" placeholder="Email
address" required>
</div><br>
<div class="input-group margin-bottom-sm">
<span class="input-group-addon">
<i class="fa fa-phone fa-fw" style="color:grey"></i>
</span>
<input class="form-control" type="text" name="phone" placeholder="Phone">
</div><br>
</div>
<div class="input-group margin-bottom-sm">
<span class="input-group-addon">
<i class="fa fa-comment-o fa-fw" style="color:grey">
</i></span>
<textarea class="form-control" rows="6" type= "text" name="message"
placeholder="Your Message" required></textarea>
</div><br>
<div class="input-group margin-bottom-sm">
<input class="form" type="hidden" name="check" value="0">
<input class="form" type="checkbox" name="check" value="1"><span
</div>
<br><br>
<div class="input-group margin-bottom-sm"><span class="input-group-addon">
<i class="fa fa-lock fa-fw" style="color:grey"></i>
</span>
<input class="form-control" type="text" name="code" placeholder="For
security, please type SECURE in this field">
</div><br>
<input class="btn btn-primary send" type="submit" value="Send Message">
</form>
<?php
$errors = '';
$myemail = 'info@xyz.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']))
{
$errors .= "
Error: all fields are required";
}
$name = $_POST['name'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$check = $_POST['check'];
// if data is posted, set value to 1, else to 0
$check = isset($_POST['check']) ? 1 : 0;
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "
Error: Invalid email address";
}
if (strtolower($_POST['code']) != 'SECURE') {die('Wrong access code');
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message from the
Mail Handler. ".
" Here are the details:
Name: $name
Phone: $phone
Email:
$email_address
Message:
$message
Signup: $check";
$headers = "From: $myemail
";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.php');
}
?>