PHP电子邮件重定向不工作验证错误


PHP Emailer Redirect Not Working for Verification Error

好吧,我有点困惑,因为这段代码是工作的,由于某种原因已经停止了。不知道什么时候它停止工作,但有人在这个网站上为我创建了它,它是完美的,当它工作。这个人把我的mail .php,重定向页面和html代码都放在一个很棒的页面里。成功页面提交作品,但验证码错误自动停止工作(?)。

代码如下:

 <?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@hotmail.com", 'Website Inquiry '.$subject, "'n'n".'Name: '.$name."'n'n".'Company: '.$company."'n'n".'Phone Number: '.$phone."'n'n".'Contact Me By: '.$ContactMethod."'n'n".'City: '.$city."'n'n".'I am Interested In: '.$InterestedIn."'n'n".'Comments: '.$comments."'n'n".$from."'n'n".$_SERVER['REMOTE_ADDR'], "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) {  ?>
<form action="" method="post" name="form1" id="form1" onsubmit="MM_validateForm('email','','RisEmail','name','','R','verif_box','','R','comments','','R');return document.MM_returnValue">

联系人表单

请填写下面的表格,以便我们的销售团队与您联系

  <p><strong>Tell us what you're interested in:</strong></p>
<dl>
  <dd>
<input type="radio" name="InterestedIn" value="BIBS<?php echo $_GET['InterestedIn'];?>"> Blow-In-Blanket System
    <input type="radio" name="InterestedIn" value="Spray Foam<?php echo $_GET['InterestedIn'];?>"> Soya Spray Foam
    <input type="radio" name="InterestedIn" value="Attic Insulation<?php echo $_GET['InterestedIn'];?>"> Attic Insulation
    <input type="radio" name="InterestedIn" value="Not Sure<?php echo $_GET['InterestedIn'];?>" checked="checked"> Not Sure</dd>
</dl>
<p><strong>Enter additional comments* in the space provided below:</strong></p>
<dl>
    <dd><textarea name="comments" cols="50" rows="5" border="0" id="comments"><?php echo $_GET['comments'];?></textarea></dd>
</dl>
<p><strong>Tell us how to get in touch with you:</strong></p>
<dl>
    <dd>
    <table>
        <tr>
            <td>Name*</td>
            <td>
            <input type="text" size="40" maxlength="256" name="name" id="name" value="<?php echo $_GET['name'];?>"></td>
        </tr>
        <tr>
            <td>Company</td>
            <td>
            <input type="text" size="40" maxlength="256" name="company" value="<?php echo $_GET['company'];?>"></td>
        </tr>
        <tr>
            <td>Email*</td>
            <td><input type="text" size="40" maxlength="256" name="email" id="email" value="<?php echo $_GET['email'];?>"></td>
        </tr>
        <tr>
            <td>Phone</td>
            <td><input type="text" size="40" maxlength="256" name="phone" value="<?php echo $_GET['phone'];?>"></td>
        </tr>
        <tr>
            <td>City</td>
            <td><input type="text" size="40" maxlength="256" name="city" value="<?php echo $_GET['city'];?>"></td>
        </tr>
    </table>
    </dd>
</dl>
    <p><strong>Best method to get in touch with you:</strong></p>
<dl>
    <dd><input type="radio" name="ContactMethod" value="telephone<?php echo $_GET['InterestedIn'];?>" checked="checked">  Phone
    <input type="radio" name="ContactMethod" value="email<?php echo $_GET['InterestedIn'];?>"> Email
    </dd>
</dl>
" Alt ="验证图像,在方框中输入" width="50" height="24" align="top"/>  

输入验证图像
<p style="padding-left:60px;"><input type="submit" class="button primary" value="Submit Form" name="submit"/>
<input type="reset" class="button primary" value="Clear Form" name"clear" /></p>

,然后在页面底部/html标签后面:

<?php } else if ($state == 1) { ?>
    <h3>Error</h3>
  <p>Wrong Verification Code Entered - Go back and try again</p>
<?php } else if ($state == 2) { ?>
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

,然后剩下的HTML在这里…对于成功提交的页面,然后是关闭PHP标记。

知道为什么它停止工作了吗?有什么方法来解决这个问题,在当前的代码?如果没有,我需要某种方式告诉表单的用户他们提交了错误的验证码。目前,如果您输入了错误的代码,它只会刷新当前页面。

任何帮助都将非常感激。我不是很精通php,所以请使用lamens术语!

Javascript:

<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && 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<(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<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<min || max<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 == '');
}
//-->
</script>

Verificationimage.php文件代码:

<?php
// ----------------------------------------- 
//  The Web Help .com
// ----------------------------------------- 
header('Content-type: image/jpeg');
$width = 50;
$height = 24;
$my_image = imagecreatetruecolor($width, $height);
imagefill($my_image, 0, 0, 0xFFFFFF);
// add noise
for ($c = 0; $c < 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);
?>

验证图像文件是一个很大的缺失部分。这就是饼干被设定的地方。看起来可能是脚本顶部的一行代码被意外删除,从而导致了您的问题。除非它没有被复制。我不知道你的验证图像的html字段名是什么,但在最上面一行你应该有这样的内容:

$verif_box = $_POST['verification_field'];

你没有设置$verif_box变量的值,所以它总是会失败。