reCAPTCHA在我的服务器上工作,但在客户端服务器上不工作

时间:2018-11-10 08:03:23

标签: server recaptcha migrate

我已经将我在自己的网站上使用过的有效的Recaptcha安全联系表落实到客户网站上。当在我自己的站点旁边的服务器上托管时,所有表单都可以正常工作。

经过测试,我将客户的站点上传到他们的服务器。但是,再次进行重新测试后,它似乎无法正常工作。我所做的就是更换钥匙。重新提交会自动打钩,并且提交后表单会跳到提交页面,就像一切正常一样,但是不会发送到我的收件箱。

下面使用了我使用的php,它在迁移服务器之前在我的网站及其网站上都能正常工作。

<?php
    function post_captcha($user_response) {
        $fields_string = '';
        $fields = array(
            'secret' => 'key',
            'response' => $user_response
        );
        foreach($fields as $key=>$value)
        $fields_string .= $key . '=' . $value . '&';
        $fields_string = rtrim($fields_string, '&');

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
        curl_setopt($ch, CURLOPT_POST, count($fields));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);

        $result = curl_exec($ch);
        curl_close($ch);

        return json_decode($result, true);
    }

    // Call the function post_captcha
    $res = post_captcha($_POST['g-recaptcha-response']);

    if (!$res['success']) {
        // What happens when the CAPTCHA wasn't checked
        echo "<script>alert('Please make sure you check the security CAPTCHA box.');</script>";
    } else {
        // If CAPTCHA is successfully completed...

        $to="email";
        $name=$_REQUEST['name'];
        $email=$_REQUEST['email'];
        $phone=$_REQUEST['phone'];
        $area=$_REQUEST['area'];
        $option=$_REQUEST['option'];
        $message=$_REQUEST['message'];
        $MESSAGE_BODY = "Name: ".$name."\n";
        $MESSAGE_BODY .= "Email: ".$email."\n";
        $MESSAGE_BODY .= "Phone No: ".$phone."\n";
        $MESSAGE_BODY .= "Area: ".$area."\n";
        $MESSAGE_BODY .= "Subject enquiry: ".$option."\n";
        $MESSAGE_BODY .= "Message: ".$message.""; 

        $from="From: $name <$email>\r\nReturn-path: $email";
        $subject="Website Enquiry - $option";
        mail($to, $subject, $MESSAGE_BODY, $from);
        header('Location: submit.html');

    }
?>

任何想法将不胜感激!

0 个答案:

没有答案