Hello I am very new to daniweb but have been using it for many years to help me learn web development. I am struggling with some code that I hope you guys might be able to help me with. I want to send checkbox data from a form my email address.


<form name="feedback-form" id="feedback-form" action="" method="post">
Name: <input name="name" type="text"  size="20" maxlength="30" class="required">
Email: <input name="email" type="text" size="20" maxlength="30" class="required">
Your favorite name?
<input type="checkbox" name="id[1]" value="1" /> Mike <br />
<input type="checkbox" name="id[2]" value="1" /> John <br />
<input type="checkbox" name="id[3]" value="1" /> George <br />
<input type="checkbox" name="id[4]" value="1" /> Jane <br />
<input type="checkbox" name="id[5]" value="1" /> Sarah <br />

<input type="Submit" value="Send Message">


if ($_POST["email"]<>'') { 

	$ToEmail = 'EMAILADDRESS'; 
	$EmailSubject = 'Video Feed Back'; 
	$mailheader = "From: ".$_POST["email"]."\r\n"; 
	$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
	$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";

	$MESSAGE_BODY = "".$_POST["name"]." posted some feedback on Light Move Image.   See The feedback below.<br>"; 

	$MESSAGE_BODY .= "<b>Name:</b> ".$_POST["name"]."<br>";
	$MESSAGE_BODY .= "<b>E-mail:</b> ".$_POST["email"]."<br>";
	$MESSAGE_BODY .= "<b>Favourite Name:</b> ".$_POST["id"]."<br>";

	mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 

I have tried to change the checkbox to an array but it is still not working. Does anybody have any ideas?

Recommended Answers

All 4 Replies

I believe you only get a value back if the checkbox is checked.

Download the debug script I posted and you can inspect the $_POST variables and see if checkbox is indeed there or not.

Debug Code

<form name="feedback-form" id="feedback-form" action="" method="post">Name: <input name="name" type="text"  size="20" maxlength="30" class="required">Email: <input name="email" type="text" size="20" maxlength="30" class="required">Your favorite name?
<input type="checkbox" name="id" value="1" /> Mike <br />
<input type="checkbox" name="id" value="2" /> John <br />
<input type="checkbox" name="id" value="3" /> George <br />
<input type="checkbox" name="id" value="4" /> Jane <br />
<input type="checkbox" name="id" value="5" /> Sarah <br />
</td></tr> <input type="Submit" value="Send Message"></form>

Depending on the value u get on the other end u can understand what was checked

1. Use an array variable in as the name for your all checkbox like below

<input type="checkbox" name="id[]" value="Mike" /> Mike 
<input type="checkbox" name="id[]" value="John" /> John

2. Use $_POST to get the selected checkbox values in an array
Your $_POST contains the selected values
[0] => Mike
[1] => John

yes manuz is right... use array <input type="checkbox" name="id[]" value="Mike" /> instead of single value input <input type="checkbox" name="id" value="Mike" />. As i examine your code there's no wrong in the php mail syntax... so it should work. i dont know if u set up correctly your mail server or other problem i see is you forgot to close your if statement

if ($_POST["email"]<>'') {
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.