我有一个联系人PHP联系人文件, 我在联系表单下的HTML主题中添加了reCAPTCHA 但我希望代码确保客户或想要联系的人通过了reCAPTCHA ..!
这是我的PHP联系人代码:
<?
$name = $_POST[name];
$email = $_POST[email];
$type = $_POST[type];
$message = $_POST[message];
if ($name == "") {
die('name null');
}
if ($type == "" || $email == "" || $message == "") {
die("not null");
}
$myemail = "myemail@myemail.com";
$s = "$name";
$body = "<b>Message from Client</b> <br><br> Name: <b>$name</b><br> Package: <b>$type</b><br> E-mail: <b>$email</b><br> Message: <b>$message</b>";
$headers = 'From: '.$email."\r\n".'Content-Type: text/html; charset=utf-8'."\r\n";
mail($myemail, $s, $body, $headers);
header('Content-Type: application/json');
echo json_encode(array('response' => 'success'));
?>
答案 0 :(得分:0)
使用if语句,检查输入的验证码是否与定义的相同。也许粘贴表格标记?看看你正在使用哪种验证码?
答案 1 :(得分:0)
尝试使用here中的此片段:
<?php
require_once('recaptchalib.php');
$privatekey = "your_private_key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
}
?>