Recaptcha 验证失败:请检查验证码

Recaptcha validation fail: please check the captcha

相关表格:

     <script language="JavaScript" src="gen_validatorv4.js" type="text/javascript"></script>
        <script src='https://www.google.com/recaptcha/api.js'></script>
   <div id="contactform">
            <div id="details">
        <form method="POST" name="contactform" action="contact-form-handler.php"> 
            <p>
                <label for='name'>Full name *:</label><br>
                <input type="text" name="name">
            </p>
            <p>
                <label for='address'>Address *:</label><br>
                <input type="text" name="address">
            </p>
            <p>
                <label for='unit'>Unit:</label><br>
                <input type="text" name="unit">
            </p>
            <p>
                <label for='postal'>Postal code *:</label><br>
                <input type="text" name="postal">
            </p>
            <p>
                <label for='email'>Email:</label> <br>
                <input type="text" name="email">
            </p>
            <p>
                <label for='phone'>Telephone *:</label><br>
                <input type="text" name="phone">
            </p>
             <p>
                <label for='date'>Preferred pickup date* :</label> <br>
                <input type="date" name="date">
            </p>
            <p>
                <label for='time'>Preferred timeslot* :</label><br>
                <span id="small">Please provide us with a 2 Hr time slot<br> (10% discount if we don't make it in time <strong>after we agreed</strong> on a timeslot</span><br>
                <input type="text" name="time1"> to <input type="text" name="time2">
            </p>
            </div>
            <div id="products">

            <p><label for='itemsharp'>Items for sharpening:</label><br>
                <textarea name="itemsharp"></textarea>
            </p>
            <p>
                <label for='itemrepair'>Items for repair:</label><br>
                <textarea name="itemrepair"></textarea>
            </p>
            <p>
                <label for='comment'>Comment: </label><br>
                <textarea name="comment"></textarea>
            </p>
            <div class="g-recaptcha" data-sitekey="[mysitekey]" data-theme="dark"></div>
            <input class="button" type="submit" value="Submit"><br>
        </form>
            </div>
        </div>

php:

<?php 
$errors = '';
$myemail = '[aperfectlyvalidemailadress]';//<-----Put Your email address here.
if(empty($_POST['name'])  || 
   empty($_POST['email']) || 
   empty($_POST['address']) ||
   empty($_POST['postal']) ||
   empty($_POST['date']) ||
   empty($_POST['time1']) ||
   empty($_POST['time2']) ||
   empty($_POST['phone']))
{
    $errors .= "\n Error: fields with a * are required";
}


$name = $_POST['name']; 
$email_address = $_POST['email'];
$address  = $_POST['address'];
$postal = $_POST['postal'];
if(!empty($_POST['unit'])){
    $unit = $_POST['unit'];
}
$phone = $_POST['phone'];
$date = $_POST['date'];
$time1 = $_POST['time1'];
$time2 = $_POST['time2'];
$itemsharp = $_POST['itemsharp'];
$itemrepair = $_POST['itemrepair'];
$comment = $_POST['comment'];

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address))
{
    $errors .= "\n Error: Please provide a valid email address";
}

       $captcha;
        if(isset($_POST['g-recaptcha-response'])){
          $captcha=$_POST['g-recaptcha-response'];
        }
        if(!$captcha){
          echo '<h2>Please check the captcha form.</h2>';
          exit;
        }
        $secretKey = "[mysecretkeyisfilledinhere]";
        $ip = $_SERVER['REMOTE_ADDR'];
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
        $responseKeys = json_decode($response,true);
        if(intval($responseKeys["success"]) !== 1) {
          echo '<h2>You are spammer ! Get the @$%K out</h2>';
        } else {

if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Sharpening request: $name";
    $email_body = "You have received a new sharpening request. ".
    "From:\n Name: $name \n Email: $email_address \n Phone: $phone \n Address: $address $unit $postal \n \n Date: $date \n Between: $time1 and $time2 \n Items for sharpening: $itemsharp \n Items for repair: $itemrepair \n Comment: \n $comment "; 

    $headers = "From: request@sharpsteel.ca\n"; 
    $headers .= "Reply-To: $email_address";

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: requestthankyou.html');
} 
        }
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
    <title>Request failed</title>
</head>

<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>


</body>
</html>

其中大部分是从各种来源拼凑而成的。我的php没那么强

我在第一次创建它时对其进行了测试,它运行良好。

现在该站点已上线,但...什么都没有。任何提交表单的尝试都会导致 "please check the captcha" 错误页面。我什么都没改变,这就是为什么我有点沮丧。

出于显而易见的原因,我在这里隐藏了电子邮件地址和密钥。

我已经查看了其他问题,但它们要么不相关(使用对我来说不同且不熟悉的语言),要么我根本不明白,对此我深表歉意。

如有任何帮助,我们将不胜感激。

html 表单存在明确的标记问题 - div 标签破坏了表单。

下面的标记看起来完全相同,但请放心,表单的代码和 div 标签已更改以确保表单有效。

<script language="JavaScript" src="gen_validatorv4.js" type="text/javascript"></script>
<script src='https://www.google.com/recaptcha/api.js'></script>
<div id="contactform">
    <form method="POST" name="contactform" action="contact-form-handler.php">
        <div id="details">
            <p>
                <label for='name'>Full name *:</label>
                <br>
                <input type="text" name="name">
            </p>
            <p>
                <label for='address'>Address *:</label>
                <br>
                <input type="text" name="address">
            </p>
            <p>
                <label for='unit'>Unit:</label>
                <br>
                <input type="text" name="unit">
            </p>
            <p>
                <label for='postal'>Postal code *:</label>
                <br>
                <input type="text" name="postal">
            </p>
            <p>
                <label for='email'>Email:</label>
                <br>
                <input type="text" name="email">
            </p>
            <p>
                <label for='phone'>Telephone *:</label>
                <br>
                <input type="text" name="phone">
            </p>
            <p>
                <label for='date'>Preferred pickup date* :</label>
                <br>
                <input type="date" name="date">
            </p>
            <p>
                <label for='time'>Preferred timeslot* :</label>
                <br>
                <span id="small">Please provide us with a 2 Hr time slot<br> (10% discount if we don't make it in time <strong>after we agreed</strong> on a timeslot</span>
                <br>
                <input type="text" name="time1"> to
                <input type="text" name="time2">
            </p>
        </div>
        <div id="products">
            <p>
                <label for='itemsharp'>Items for sharpening:</label>
                <br>
                <textarea name="itemsharp"></textarea>
            </p>
            <p>
                <label for='itemrepair'>Items for repair:</label>
                <br>
                <textarea name="itemrepair"></textarea>
            </p>
            <p>
                <label for='comment'>Comment: </label>
                <br>
                <textarea name="comment"></textarea>
            </p>
            <div class="g-recaptcha" data-sitekey="[mysitekey]" data-theme="dark"></div>
            <input class="button" type="submit" value="Submit">
            <br>
        </div>
    </form>
</div>