PHP email with Checkbox


Having issues getting my very simple email form to work. What I want to happen is the email will only send if the form checkbox has been selected.


<form class="form-inline contact_box" action="contact.php" method="post">
                        <input name="cf_name" class="form-control input_box" type"text" placeholder="Full Name" required>
                        <input name="cf_email" class="form-control input_box" type"text"  placeholder="Email" required>
                        <input name="cf_subject" class="form-control input_box" type"text"  placeholder="Subject" required>
                        <textarea name="cf_message" class="form-control input_box" rows="20" placeholder="Message" required></textarea>
                        Are you human?
                        <input type="checkbox" name="question" value="Yes" />
                        <button type="submit" class="btn btn-default">Send Message</button>



$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_subject = $_POST['cf_subject'];
$field_message = $_POST['cf_message'];

$mail_to = '';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Subject: '.$field_subject."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
	<script language="javascript" type="text/javascript">
		alert('Thank you for the message. We will contact you shortly.');
		window.location = 'contact.html';
else { ?>
	<script language="javascript" type="text/javascript">
		alert('Message failed. Please, send an email to');
		window.location = 'contact.html';

Any help would be much appreciated.


And that would be due to this decision statement.


Any suggestions on how to correct it?


Change it to,


Thank you for your help. Just out of interest, how is that line of code linked to the forms checkbox?


try the key (name=):

if (isset($_POST['question'])) {

It isn’t, that’s why it works. If the form is submitted via post, it will process the request, how it get’s there is irrelevant.