我正在使用php联系表单和Google reCAPTCHA通过电子邮件发送表单数据
但它不起作用
我正在使用Google reCAPTCHA版本2
这是html代码
<?php if (isset($_POST['g-recaptcha-response'])) { $captcha = $_POST['g-recaptcha-response']; } if (!$captcha) { echo 'Please check the the captcha form.'; exit; } $secret = '6LdP61AkAAAAAKmCUXdCbJEKGwwbHhqyLGd2jsMW'; $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secret . "&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']); $response = json_decode($response); if ($response->success === false) { echo 'You are a spammer!'; } else { echo 'Thanks for posting comment.'; // Prepare email content $to = "nextr2020@gmail.com"; $subject = "Contact form submission"; $message = "Name: " . $_POST['name'] . "\n"; $message .= "Email: " . $_POST['email'] . "\n"; $message .= "Message: " . $_POST['message']; // Send email $header = "From: nextr2020@gmail.com\r\n"; if (mail($to, $subject, $message, $header)) { echo "Your email has been sent successfully."; } else { echo "Failed to send email. Please try again later."; } } ?>
我正在使用php