我曾尝试为广大一天得到这个工作,但似乎都与我的代码不完全工作。我有一个完美的工作sendmail的剧本,只是想在谷歌验证码添加。到目前为止,它不会发出接触形式,除非复选框被选中,但如果它未选中我的字段验证不工作,没有警报,告诉用户检查的ReCaptcha。但是,如果所有字段填写并复选框被选中它呼应了成功的消息。
我已经试了很多TUTS谷歌和试图按照谷歌的开发者文档,但似乎无法响应我的正确解码,并获得如果else语句吧!
//Checking For reCAPTCHA
$captcha;
if (isset($_POST['g-recaptcha-response'])) {
$captcha = $_POST['g-recaptcha-response'];
}
// Checking For correct reCAPTCHA
$response =
file_get_contents("https://www.google.com/recaptcha/api/siteverify?
secret=SECRETKEY&response=" . $captcha . "&remoteip=" .
$_SERVER['REMOTE_ADDR']);
if (!$captcha || $response.success == false) {
echo "Your CAPTCHA response was wrong.";
exit ;
} else {
session_cache_limiter( 'nocache' );
header( 'Expires: ' . gmdate( 'r', 0 ) );
header( 'Content-type: application/json' );
$to = '[email protected]'; // put your email here
$email_template = 'simple.html';
$subject = strip_tags($_POST['vsubject']);
$email = strip_tags($_POST['vemail']);
$name = strip_tags($_POST['vname']);
$message = nl2br( htmlspecialchars($_POST['vmessage'], ENT_QUOTES) );
$result = array();
if(empty($name)){
$result = array( 'response' => 'error', 'empty'=>'name', 'message'=>'<strong>Error!</strong> Name is empty.' );
echo json_encode($result );
die;
}
if(empty($email)){
$result = array( 'response' => 'error', 'empty'=>'email', 'message'=>'<strong>Error!</strong> Email is empty.' );
echo json_encode($result );
die;
}
if(empty($message)){
$result = array( 'response' => 'error', 'empty'=>'message', 'message'=>'<strong>Error!</strong> Message body is empty.' );
echo json_encode($result );
die;
}
$headers = "From: " . $name . ' <' . $email . '>' . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$templateTags = array(
'{{subject}}' => $subject,
'{{email}}'=>$email,
'{{message}}'=>$message,
'{{name}}'=>$name
);
$templateContents = file_get_contents( dirname(__FILE__) . '/inc/'.$email_template);
$contents = strtr($templateContents, $templateTags);
if ( mail( $to, $subject, $contents, $headers ) ) {
$result = array( 'response' => 'success', 'message'=>'<strong>Thank You!</strong> Your email has been delivered.' );
} else {
$result = array( 'response' => 'error', 'message'=>'<strong>Error!</strong> Cann\'t Send Mail.' );
}
echo json_encode( $result );
die;
}
我只想提醒用户reCatpcha未选中并发送,如果是,也将是不错的我所有的sendmail.php才能正常工作。即如果姓名,电子邮件或消息空旷的回音的消息,他们似乎越来越错过了什么?
$response =
file_get_contents("https://www.google.com/recaptcha/api/siteverify?
secret=SECRETKEY&response=" . $captcha . "&remoteip=" .
$_SERVER['REMOTE_ADDR']);
$s = json_decode($response);
if (!$captcha || $s.success == false) {
echo "Your CAPTCHA response was wrong.";
exit ;
试试这个,它可能是直接访问该$响应不工作,你尝试登录什么$ response是一个从调试器?
<?php
session_cache_limiter( 'nocache' );
header( 'Expires: ' . gmdate( 'r', 0 ) );
header( 'Content-type: application/json' );
$to = '[email protected]'; // put your email here
$email_template = 'simple.html';
$subject = strip_tags($_POST['vsubject']);
$email = strip_tags($_POST['vemail']);
$name = strip_tags($_POST['vname']);
$message = nl2br( htmlspecialchars($_POST['vmessage'], ENT_QUOTES) );
$result = array();
if(empty($email)){
$result = array( 'response' => 'error', 'empty'=>'email', 'message'=>'<strong>Error!</strong> Email is empty.' );
echo json_encode($result );
die;
}
if(empty($name)){
$result = array( 'response' => 'error', 'empty'=>'name', 'message'=>'<strong>Error!</strong> Name is empty.' );
echo json_encode($result );
die;
}
if(empty($message)){
$result = array( 'response' => 'error', 'empty'=>'message', 'message'=>'<strong>Error!</strong> Message body is empty.' );
echo json_encode($result );
die;
}
if(empty($_POST['g-recaptcha-response'])) {
$result = array( 'response' => 'error', 'empty'=>'message', 'message'=>'<strong>Error!</strong> Please complete the Captcha.' );
echo json_encode($result );
die;
}
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
$secret = '6LeSSI0UAAAAAFnwmu5cj7bk4guiaoXXnlID5-C2';
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if($responseData->success == true) {
$headers = "From: " . $name . ' <' . $email . '>' . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$templateTags = array(
'{{subject}}' => $subject,
'{{email}}'=>$email,
'{{message}}'=>$message,
'{{name}}'=>$name
);
$templateContents = file_get_contents( dirname(__FILE__) . '/inc/'.$email_template);
$contents = strtr($templateContents, $templateTags);
if ( mail( $to, $subject, $contents, $headers ) ) {
$result = array( 'response' => 'success', 'message'=>'<strong>Thank You!</strong> Your email has been delivered.' );
} else {
$result = array( 'response' => 'error', 'message'=>'<strong>Error!</strong> Can\'t Send Mail.' );
}
echo json_encode( $result );
die;
}
else
{
echo "<p> Sorry verification valid</p>";
}
}
?>
所以有一点玩耍和阅读我的代码回自己,我已经能够得到的一切,除了不知道如何恢复验证码的工作!
所以,最后我得到了所有空字段验证工作,之后他们的条件都满足时提醒用户打勾,如不这样做的话,然后才将其发送表单提交和成功消息的警报用户的验证码。唯一的问题现在重新验证码。