2

我需要你的帮助来解决我的问题。我在过去 4-5 年使用 Google recaptcha V2,它工作正常,但突然显示以下错误:- 我们检测到您的网站没有验证 reCAPTCHA 解决方案。这是在您的网站上正确使用 reCAPTCHA 所必需的。请查看我们的开发者网站了解更多信息。

我的代码:-

<?php
if(isset($_POST['submit'])):
    if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
        //your site secret key
        $secret = 'keykeykeykeykeykeykeykeykeykeykey';
        //get verify response data
        $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
        $responseData = json_decode($verifyResponse);
        
        $name = !empty($_POST['name'])?$_POST['name']:'';
        $email = !empty($_POST['email'])?$_POST['email']:'';
        $phone = !empty($_POST['phone'])?$_POST['phone']:'';
        $message = !empty($_POST['message'])?$_POST['message']:'';
        if($responseData->success):
            //contact form submission code
            $to = 'info@greve.com';
            $subject = 'Query Received from '.$name;
            $htmlContent = "
                <p><b>Name: </b>".$name."</p>
                <p><b>Email: </b>".$email."</p>
                <p><b>Contact No.: </b>".$phone."</p>
                <p><b>Message: </b>".$message."</p>
            ";
            // Always set content-type when sending HTML email
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            $headers .= 'From: GREVE Main <info@greve.com>' . "\r\n";
            //send email
            @mail($to,$subject,$htmlContent,$headers);
            
            $succMsg = 'Your contact request have submitted successfully.';
            $name = '';
            $email = '';
            $phone = '';
            $message = '';
        else:
            $errMsg = 'Robot verification failed, please try again.';
        endif;
    else:
        $errMsg = 'Please click on the reCAPTCHA box.';
    endif;
else:
    $errMsg = '';
    $succMsg = '';
    $name = '';
    $email = '';
    $phone = '';
    $message = '';
endif;
?>

表格代码:-

<div>
    <?php if(!empty($errMsg)): ?><div class="errMsg"><?php echo $errMsg; ?></div><?php endif; ?>
    <?php if(!empty($succMsg)): ?><div class="succMsg"><?php echo $succMsg; ?></div><?php endif; ?>
</div>

                        <form class="row call_back_form" action="" method="post">
  <table class="tab-font" width="80%" border="0" cellspacing="3" cellpadding="0" style="margin-left:15px;">
    <tr>
      <td align="left" valign="top">Your Name: <span class="red">*</span></td>
    </tr>
    <tr>
      <td align="left" valign="top"><input type="text" class="form-control" value="<?php echo !empty($name)?$name:''; ?>" name="name" ></td>
    </tr>
    <tr>
      <td align="left" valign="top">Your Email: <span class="red">*</span></td>
    </tr>
    <tr>
      <td align="left" valign="top"><input type="text" class="form-control" value="<?php echo !empty($email)?$email:''; ?>" name="email" ></td>
    </tr>
    <tr>
      <td align="left" valign="top">Contact No.: <span class="red">*</span></td>
    </tr>
    <tr>
      <td align="left" valign="top"><input type="text" class="form-control" value="<?php echo !empty($phone)?$phone:''; ?>" name="phone" ></td>
    </tr>
    <tr>
      <td align="left" valign="top">Your Message: <span class="red">*</span></td>
    </tr>
    <tr>
      <td align="left" valign="top"><textarea class="form-control" type="text" required name="message"><?php echo !empty($message)?$message:''; ?></textarea></td>
    </tr>
    <tr>
      <td align="left" valign="top"><div class="g-recaptcha" data-sitekey="6LdBzRMUAAAAALB3B_Jq11dcHeEf2d5jwxw2IBLm"></div></td>
    </tr>
    <tr>
      <td align="left" valign="top"><span style="color:#F00;">*</span>Read our updated <a href="terms.html" target="_blank">Terms of Use</a> and <a href="privacy.html" target="_blank">Privacy Policy</a> before submitting your query.</td>
    </tr>
    <tr>
      <td align="left" valign="top"><input type="submit" style="padding-bottom: 20px; padding-top: 10px; height: 65px;" class="btn submit_btn form-control" name="submit" value="SEND MESSAGE"></td>
    </tr>
  </table>
</form>
4

0 回答 0