PHP Email Form: Wrong Verification Entered Message Not Working Anymore?
<p>Okay, I have tried asking different people for help and have been unsuccessful at getting an answer. Here is all of the code which was working perfect and I have no idea when it stopped working. If someone could take a look at it for me, it would be greatly appreciated. </p>

<p>The website is at <a href="http://markreeder.ca" rel="nofollow">http://markreeder.ca</a> in case someone wants to see what happens when the wrong verification code is entered. All it does now is clear the wrong code without giving an error message. The error message was working when the site went online back in August. If no one can figure out how to correct it, is it possible to do a different type of error message? Maybe similar to the required fields error message currently being used? PHP is not my strong point, so I could really use some assistance here. This is driving me a little crazy. </p>

<p>Here is the javascript from header section:</p>

<pre><code>&lt;script type="text/JavaScript"&gt;
&lt;!--
function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))&gt;0&amp;&amp;parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&amp;&amp;d.all) x=d.all[n]; for (i=0;!x&amp;&amp;i&lt;d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&amp;&amp;d.layers&amp;&amp;i&lt;d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x &amp;&amp; d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i&lt;(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
    if (p&lt;1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
  } else if (test!='R') { num = parseFloat(val);
    if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
    if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
      min=test.substring(8,p); max=test.substring(p+1);
      if (num&lt;min || max&lt;num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//--&gt;
&lt;/script&gt;
</code></pre>

<p>Here is the orginal php form:</p>

<pre><code>&lt;?php
$state = 0;
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
// if verification code was correct send the message and show this page
mail("MYEMAIL@gmail.com", 'Online Form: '.$subject, "\n".$comments." 
\n\n".$name."\n\n".$lastname."\n\n".$from."\n\n".$_SERVER['REMOTE_ADDR']."\n\n".'mailinglist: '.$mailinglist, "From: $email");
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
$state = 2;
} else if(isset($message) and $message!=""){
// if verification code was incorrect then return to contact page and show error
$state = 1;
}

if ($state == 0) {  ?&gt;
&lt;form action="" method="post" name="form1" id="form1" 

  onsubmit="MM_validateForm('email','','RisEmail','name','','R','verif_box','','R','comments','','R')

 ;return document.MM_returnValue"&gt;


&lt;input type="text" name="name" size="37" border="0" id="name" value="&lt;?php echo $_POST['name'];?&gt;"&gt; 

&lt;input type="text" name="lastname" size="37" border="0" id="lastname" value="&lt;?php echo $_GET['lastname'];?&gt;"&gt;

&lt;input type="text" name="email" size="37" border="0" id="from" value="&lt;?php echo $_POST['email'];?&gt;"&gt; 

&lt;input type=checkbox name="mailinglist" id="mailinglist" value="Yes&lt;?php echo $_POST['mailinglist'];?&gt;"&gt;

&lt;textarea name="comments" cols="35" rows="10" border="0" id="comments"&gt;&lt;?php echo $_POST['comments'];?&gt;&lt;/textarea&gt;&lt;br&gt; &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt; 


&lt;img src="verificationimage.php?&lt;?php echo rand(0,9999);?&gt;" alt="verification image, type it in the box" width="50" height="24" align="top" /&gt;&amp;nbsp;&amp;nbsp;&lt;input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid #CCCCCC; width:80px; height:14px;"/&gt;&lt;br /&gt;&lt;br /&gt;
Enter Verification Image



&lt;input name="Submit" type="submit" style="margin-top:10px; display:block; border:1px solid #000000; width:100px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px; padding-left:2px; padding-right:2px; padding-top:0px; padding-bottom:2px; line-height:14px; background-color:#EFEFEF;" value="Send Message"/&gt;

&lt;input type="reset" class="btn" value="  clear  " name="Clear" border="0" style="margin-top:10px; display:block; border:1px solid #000000; width:100px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px; padding-left:2px;  padding-top:0px; padding-bottom:2px; line-height:14px; background-color:#EFEFEF;"&gt;
</code></pre>

<p></p>

<p>Here is the php after closing html tag:</p>

<pre><code>&lt;?php } else if ($state == 1) { ?&gt;
   Wrong Verification Code Entered - Go back and try again


&lt;?php } else if ($state == 2) { ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
Your message has been sent successfully.
</code></pre>

<p>Then the imageverification.php file code:</p>

<pre><code>&lt;?php

header('Content-type: image/jpeg');

$width = 50;
$height = 24;
$verif_box = $_POST['verif_box'];

$my_image = imagecreatetruecolor($width, $height);

imagefill($my_image, 0, 0, 0xFFFFFF);

// add noise
for ($c = 0; $c &lt; 40; $c++){
$x = rand(0,$width-1);
$y = rand(0,$height-1);
imagesetpixel($my_image, $x, $y, 0x000000);
}

$x = rand(1,10);
$y = rand(1,10);

$rand_string = rand(1000,9999);
imagestring($my_image, 5, $x, $y, $rand_string, 0x000000);

setcookie('tntcon',(md5($rand_string).'a4xn'));

imagejpeg($my_image);
imagedestroy($my_image);
?&gt;
</code></pre>

<p>Any input would be appreciated... </p>
