PHP Emailer重定向不适用于验证错误

时间:2011-10-27 13:43:24

标签: php

好的,我有点困惑,因为这段代码正在运行,并且出于某种原因已经停止了。不确定它什么时候停止工作,但是这个网站上的某个人为我创建了它并且它在工作时非常完美。该人将我的mailer.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“/&gt;

输入验证图像
<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);
?>

1 个答案:

答案 0 :(得分:0)

验证图像文件是一个很大的缺失部分。这就是设置cookie的地方。看起来脚本顶部的一行代码可能会被意外删除,从而导致您的问题。除非它没有被复制。我不知道你的验证图像的html字段名称是什么,但在最顶层你应该有类似的东西:

$ verif_box = $ _POST ['verification_field'];

您没有为$ verif_box变量设置值,因此它总是会失败。