繁体   English   中英

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

[英]PHP Emailer Redirect Not Working for Verification Error

好的,我有点困惑,因为此代码正在运行并且由于某种原因已停止。 不知道它什么时候停止工作,但是这个站点上的某人为我创建了它,当它工作时它是完美的。 这个人将我的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“ />

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

verifyimage文件是一个很大的缺失部分。 这就是设置cookie的地方。 似乎脚本顶部的一行代码被意外删除,从而导致了问题。 除非它不是被复制进来的。否则我无法确定您的验证图像的html字段名称是什么,但是在最上面一行应该有以下内容:

$ verif_box = $ _POST ['verification_field'];

您没有为$ verif_box变量设置值,因此它将始终失败。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM