I have created a message form in my website, now I am adding a text box to it. I am getting the checkbox value is ON in the email if checkbox checked blank if unchecked.
I have to make the text Checkbox checked
if Checked and Checkbox Unchecked
if unchecked instead of Blank & ON Value.
Here is my Contact Form HTML
<div class="contact-form">
<form id="contact-form" method="post" action="php/contact-form-handler.php">
<input name="name" type="text" class="form-control" placeholder="Your Name" required="required" />
<br />
<input name="email" type="email" class="form-control" placeholder="Your Email" required="required" />
<label class="form-label opt-in-label"><input type="checkbox" class="opt-in-checkbox" name="checkbox"><span class="opt-in">Check here to receive email updates</span></label>
<input name="subject" type="text" class="form-control" placeholder="Subject" required="required" />
<textarea name="message" class="form-control" placeholder="Message" row="10" required="required" /></textarea>
<br />
<input type="submit" class="from-control submit" value="SEND MESSAGE" />
</form>
</div>
Here is the PHP code
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$checkbox = $_POST['checkbox'];
$email_from = 'xxx@gmail.com';
$email_subject = "New Form Submission";
$email_body = "User Name: $name\n".
"User Email: $visitor_email\n".
"Checkbox: $checkbox\n".
"Subject: $subject\n".
"User Message: $message\n";
$to = "yyy@gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: /contact-us.html");
?>