Hello,
I have been searching all over the internet for a way to get multiple check boxes to print to an email.
I have been working on this for days and I just can’t seen to find a way to do it. Everything works fine except for the check boxes, I have tried many many different snippets of code to try to get this to email me the results of the checked boxes.
Can you please help me to get this working?
Any help would greatly appreciate it.
The code I am using is below
DeZiner
[php][php]<?php
$your_email =‘[email protected]’;// <<=== update to your email address
session_start();
$errors = ‘’;
$name = ‘’;
$visitor_email = ‘’;
$user_message = ‘’;
if(isset($_POST[‘submit’]))
{
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$visitor_q1 = $_POST['q1'];
$gender = $_POST['gender'];
$Preferred = $_POST['preflang'];
$user_message = $_POST['message'];
///------------Do Validations-------------
if(empty($name)||empty($visitor_email))
{
$errors .= "\n Name and Email are required fields. ";
}
if(IsInjected($visitor_email))
{
$errors .= "\n Bad email value!";
}
if(empty($_SESSION['6_letters_code'] ) ||
strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
{
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "\n The captcha code does not match!";
}
if(empty($errors))
{
//send the email
$to = $your_email;
$subject="New form submission";
$from = $your_email;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$body = "A user $name submitted the contact form:\n".
"Full Name: $name\n".
"Email: $visitor_email \n".
"Gender: $gender \n".
"Preferred Language: $preflang \n".
"Q1: $visitor_q1 \n".
"Message: \n ".
"$user_message\n".
"IP: $ip\n";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $subject, $body,$headers);
header('Location: thank_you.htm');
}
}
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array(’(\n+)’,
‘(\r+)’,
‘(\t+)’,
‘(%0A+)’,
‘(%0D+)’,
‘(%08+)’,
‘(%09+)’
);
$inject = join(’|’, $injections);
$inject = “/$inject/i”;
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>[/php][/php]
[code]
Untitled Document <?php if(!empty($errors)){ echo "".nl2br($errors)."
"; } ?>
Full Name:
Email:
Checkboxes:
First: <input type=“checkbox” name=“boxes[]” value=“first” <?php echo (is_array($_POST['boxes']) && in_array('first', $_POST['boxes'])) ? 'checked = "checked"' : ''; ?>>
Second: <input type=“checkbox” name=“boxes[]” value=“second” <?php echo (is_array($_POST['boxes']) && in_array('second', $_POST['boxes'])) ? 'checked = "checked"' : ''; ?>>
Third: <input type=“checkbox” name=“boxes[]” value=“third” <?php echo (is_array($_POST['boxes']) && in_array('third', $_POST['boxes'])) ? 'checked = "checked"' : ''; ?>>
Q1:
My gender is:
<input type=“radio” name=“gender” value=“male” <?php echo $_POST['gender'] == 'male' ? 'selected="selected"' : ''; ?>/>
Male:
<input type=“radio” name=“gender” value=“female” <?php echo $_POST['gender'] == 'female' ? 'selected="selected"' : ''; ?>/>
Female:
My preferred language is:
<input type=“radio” name=“preflang” value=“en” <?php echo $_POST['preflang'] == 'en' ? 'selected="selected"' : ''; ?>/>
English:
<input type=“radio” name=“preflang” value=“fr” <?php echo $_POST['preflang'] == 'fr' ? 'selected="selected"' : ''; ?>/>
Français:
<input type=“radio” name=“preflang” value=“es” <?php echo $_POST['preflang'] == 'es' ? 'selected="selected"' : ''; ?>/>
Español:
Message:
<?php echo htmlentities($user_message) ?>
Enter the code above here :
Can't read the image? click here to refresh