Php 我无法将Recaptcha嵌入电子邮件表单
我正试图在一个我正在工作的网站上将recaptcha实现到电子邮件表单中,但是它不起作用,我不明白为什么。。。我已经删除了所有的recaptcha代码,表单工作正常,我想我的错误是在某个地方处理recaptcha,但我不确定。任何帮助都将不胜感激 这是表格Php 我无法将Recaptcha嵌入电子邮件表单,php,html,email,recaptcha,Php,Html,Email,Recaptcha,我正试图在一个我正在工作的网站上将recaptcha实现到电子邮件表单中,但是它不起作用,我不明白为什么。。。我已经删除了所有的recaptcha代码,表单工作正常,我想我的错误是在某个地方处理recaptcha,但我不确定。任何帮助都将不胜感激 这是表格 <!-- start contact form --> <form method="POST" name="contact_form" action="contact-form-handler
<!-- start contact form -->
<form method="POST" name="contact_form" action="contact-form-handler.php">
<h4>Your Name:</h4>
<input type="text" name="name" size="35">
<h4>Email Address:</h4>
<input type="text" name="email" size="35">
<h4>Message:</h4>
<textarea name="message" rows="6" cols="37"></textarea>
<div>
<script type="text/javascript"
src="http://www.google.com/recaptcha/api/challenge?k=publickey">
</script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=publickey"
height="300" width="500" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40">
</textarea>
<input type="hidden" name="recaptcha_response_field"
value="manual_challenge">
</noscript>
</div>
<div>
<input type="submit" value="Submit">
</div>
<script language="JavaScript">
var frmvalidator = new Validator("contact_form");
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
frmvalidator.addValidation("message","req","Please write a message");
frmvalidator.addValidation("recaptcha_challenge_field", "req", "Please answer the captcha test");
</script>
</form>
<!-- end contact form-->
这是处理它的后端php
<?php
require_once('/scripts/recaptcha/recaptchalib.php');
$privatekey = "PRIVATE KEY";
$resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
header('Location: contact.html')
exit;
} else {
$myemail = 'myemail';
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email_address\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
$email_body = wordwrap($email_body, 70);
mail($to,$email_subject,$email_body,$headers);
header('Location: contact_thanks.html');
exit;
}
?>
您必须在此处插入recaptcha提供的密钥:src=http://www.google.com/recaptcha/api/challenge?k=publickey 这里是src=http://www.google.com/recaptcha/api/noscript?k=publickey 用recaptcha提供的公钥替换公钥 并将recaptcha提供的私钥放在php文件中:$privatekey=privatekey 如果您仍然存在问题,则有时recaptcha会生成无效密钥,如果您不幸得到损坏的密钥,则必须等待一天左右的时间才能修复 如果您还没有这样做,要获取您的钥匙,请注册
根据我自己的经验,这是一个非常重要的注意事项,如果你的钥匙断了,重装卡根本不会出现,你也不会出错!我必须手动访问这些链接,以查看recaptcha密钥将返回500个内部服务器错误,我必须等待它们修复这些密钥 遵循此文档:我已经完成了所有这些,为了共享代码,我删除了密钥。。。我可以让验证码显示得很好,至于链接,它们似乎工作得很好,当我把它们放到浏览器中时,两者都显示出来……你可以尝试使用这个函数echo-recaptcha\u-get\u-html$public\u-key来修改验证码的显示方式;看看它是否是这样工作的,显然,现在文件应该是.php。我已经这样做了,我想这可能与数据在它们之间的传递方式有关?我总是被重定向到php文件,但从来没有超过这个。。。电子邮件也不发送。