Help with getting multi check boxes to send to email

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

[/code]

The above code is all in one file. You can see it online at

http://www.richardiv.com/captcha_form.php

Try this:
[php]if(is_array($_POST[“boxes”])) $boxes=implode(’, ',$_POST[“boxes”]);[/php]

And then add $boxes to your $body variable.

Thank you for your quick reply,
I am really bad when it comes to php. can you direct me to where I need to insert this code
Thank you for your help

I inserted it in the bold spots below with no results in including it in the email results

[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'];
[b]$boxes = $_POST['boxes'];[/b]
$user_message = $_POST['message'];
[b]if(is_array($_POST["boxes"])) $boxes=implode(', ',$_POST["boxes"]);[/b][/php]

I Think I have it

[php] $name = $_POST[‘name’];
$visitor_email = $_POST[‘email’];
$visitor_q1 = $_POST[‘q1’];
$gender = $_POST[‘gender’];
$Preferred = $_POST[‘preflang’];
$boxes = $_POST[‘boxes’];
$user_message = $_POST[‘message’];
if(is_array($_POST[“boxes”])) $boxes=implode(’, ',$_POST[“boxes”]);[/php]

and

[php] $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”.
“Boxes: $boxes \n”.
"Message: \n ".
“$user_message\n”.
“IP: $ip\n”;[/php]

Thank you for your help. If I need a php coder I know where to look.

No problem. You can also eliminate this line (it is not needed there):
[php]$boxes = $_POST[‘boxes’];[/php]

Yep I took that out already. You are the first php programmer that has been helpful with straight forward answers. Once I can see what has to happen I can study it and understand function and principal. Now I can work through a few other issues I have on my own
Thank you for all your help.

Sponsor our Newsletter | Privacy Policy | Terms of Service