我正在使用XAMPP在本地主机上运行我的代码-我有一个允许用户输入名称,电子邮件和消息的表单。我在提交按钮之前有RECAPTCHA v2小部件。当前看来,响应file_get_contents似乎实际上无法验证RECAPTCHA响应,因此它无法确定该响应是否成功。
目前,它始终会恢复“无效的验证码”。请再试一遍'。 $ response即使成功也永远不会成功。
我收到以下警告消息:
警告:加载cafile流失败:C:\ xampp \ htdocs \ oscommerce \ catalog \ recaptchaexample.php在线105上的C:\ xampp \ apache \ bin \ curl-ca-bundle.crt'
警告:file_get_contents():无法在第105行的C:\ xampp \ htdocs \ oscommerce \ catalog \ recaptchaexample.php中启用加密
警告:file_get_contents(https://www.google.com/recaptcha/api/siteverify?secret=6Lf1EaIUAAAAAEsUH5qVDPzLV0JqHf5d2RpDn155&response=&remoteip=::1):无法打开流:C:\ xampp \ htdocs \ oscommerce \ catalog \ recaptchaexample.php在行105上的操作失败
注意:尝试在第111行的C:\ xampp \ htdocs \ oscommerce \ catalog \ recaptchaexample.php中获取非对象的属性
验证码无效。请重试
<head>
<title>Contact Form Design</title>
<style type="text/css">
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
.contact-form {
box-shadow: 0 0 4px 0 4gba(0,0,0,0.5);
margin: 50px auto;
width: 350px;
text-align: center;
}
.contact-form h2 {
background: #efefef;
margin-top: 0;
padding: 10px;
}
.contact-form input {
display: block;
width: 90%;
margin: 10px;
}
.contact-form textarea {
width: 90%;
margin: 5px auto;
padding-left: 10px;
height: 80px;
}
.submit-btn {
cursor: pointer;
width: 150px !important;
margin-left: 18px;
}
.status {
font-size: 15px;
color: green;
padding: 15px;
}
</style>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<div class="contact-form">
<h2>CONTACT US</h2>
<form method="post" action="">
<input type="text" name="name" placeholder="Your name" required />
<input type="email" name="email" placeholder="Your email" required />
<textarea name="message" placeholder="Your message" required ></textarea>
<div class="g-recaptcha" data-sitekey="sitekey"></div>
<input type="submit" name="submit" value="Send Message" class="submit-btn">
</form>
<div class="status">
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$email_from = "noreply@gmail.com";
$email_subject = "New Form Submission";
$email_body = "Name: $name.\n".
"Email: $email.\n".
"Message: $message.\n";
$to_email = "toemail";
$headers = "From: $email_from \r\n";
$headers = "Reply-To: $email \r\n";
$secretKey = "secretkey";
$responseKey = $_POST['g-recaptcha-response'];
$UserIP = $_SERVER['REMOTE_ADDR'];
// Verify the reCAPTCHA response
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$responseKey.'&remoteip='.$UserIP);
// Decode json data
$response = json_decode($response);
if ($response->success)
{
mail($to_email,$email_subject,$email_body,$headers);
echo "Message sent succesfully";
}
else
{
echo "Invalid Captcha. Please try again";
}
}
?>
</div>
</div>
</body>
</html>