Hi i'm currently having problems with my code.
When i submit the form with the CAPTCHA Code submited it sends the email, but when i dont enter the code it still submits the form.

Can you tell me what i'm doing wrong.
thanks

<?php
session_start();
?>

<form action="contact.php" method="post">
<?php
if ($_POST["send"]<>'') {
if( $_SESSION['validation'] == $_POST['validation'] {
	$ToEmail = 'email@yourwebsite.com'; 
	$EmailSubject = "Contact form ".$_POST["about"];
	$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 = "Name: ".$_POST["name"]."<br>"; 
	$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
	$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>"; 
	mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
echo "Your message was sent.";
unset($_SESSION['security_code']);
} else {
	echo "Invalid Security Code";
	}
else { 
?>

<br />
<br />
<table width="400" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="29%" class="bodytext">Your name:</td>
<td width="71%"><input name="name" type="text" class="textbox" id="name" size="32"></td>
</tr>
<tr>
<td class="bodytext">Email address:</td>
<td><input name="email" type="text" class="textbox" id="email" size="32"> </td>
</tr>
<tr>
<td class="bodytext">Message:</td>
<td><textarea name="comment" cols="45" rows="6" id="comment" class="textbox"></textarea></td>
</tr>
<tr>
<td class="bodytext"><img src="CAPTCHA/?width=100&height=35&characters=5" class="textbox" /></td>
<td align="left" valign="top"><input name="validation" type="text" class="textbox" id="validation" /></td>
</tr>
<tr>
<td class="bodytext">&nbsp;</td>
<td align="left" valign="top"><input name="send" type="submit" class="button" id="send" value="Send Email »"></td>
</tr>
</table>
<p>You will receive a reply to the email address you specify from the administrator.
  <br />
  Thank you for the time you have take to fill out this form.</p>
</form> 
<?php 
}; 
?>

3 hours and no repy :(

Don't bump your posts like that, it's annoying. Where is $_SESSION being set and did you make sure that they are in fact equal, there are some debugging steps you can do yourself before you go to a forum, and if you have tried to debug it yourself what steps have you tried?

Don't bump your posts like that, it's annoying. Where is $_SESSION being set and did you make sure that they are in fact equal, there are some debugging steps you can do yourself before you go to a forum, and if you have tried to debug it yourself what steps have you tried?

1) Sorry kind of new here.

and what do you mean by debugging?
Like i have tried to remove the Captcha code and tried differant steps from the web still didnt work
also i have tried differant values in $_SESSION and $_POST

Did you seriously just ask that? Debugging, as in making sure your variables are what you think they are, making sure you haven't done anything dumb like missing a semicolon (haven't in this case) or used = instead of == in a condition, that's debugging in a nutshell. http://php.net/var_dump, http://php.net/print_r. This is not a Daniweb specific thing, this is a programming thing, get to know it well. That is, of course, unless you just copied and pasted code and have no intention of learning how to program and just want the script to work.

ok so

I think i see what i have done wrong

else {
    echo "Invalid Security Code";
}

was meant to be before the form is submited, so it is meant to check first if the code is correct then submit

i think so anyway

Like I said, start with making sure your variables are what you think they are (using print_r or var_dump)

Like I said, start with making sure your variables are what you think they are (using print_r or var_dump)

Thanks alot for your help got the code and solved

Be a part of the DaniWeb community

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