【发布时间】:2022-01-18 18:44:49
【问题描述】:
我有一个用 php 制作的联系表格,在我更改了我网站的 wordpress 部分的 php 版本之前,它发送良好,现在联系表格无法与验证码一起使用。
表单正在将联系表单发送到电子邮件,但是一旦填写表单时 php 版本发生更改,它就会返回此“请检查验证码表单”
如果我改回 php 版本,它可以正常工作,但 wordpress 将无法正常工作。有什么想法吗?
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// access
$secretKey = '6LeLKR8eAAAAAKs2E8ldKBQwfkUtiFyoozKMswhd';
$captcha = $_POST['g-recaptcha-response'];
if(!$captcha){
echo '<p class="alert alert-warning">Please check the the captcha form.</p>';
exit;
}
# FIX: Replace this email with recipient email
$mail_to = "EMAIL@EMAIL.COM";
# Sender Data
$name = str_replace(array("\r","\n"),array(" "," ") , strip_tags(trim($_POST["name"])));
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$phone = trim($_POST["phone"]);
$message = trim($_POST["message"]);
if ( empty($name) OR !filter_var($email, FILTER_VALIDATE_EMAIL) OR empty($phone) OR empty($message)) {
# Set a 400 (bad request) response code and exit.
http_response_code(400);
echo '<p class="alert alert-warning">Please complete the form and try again.</p>';
exit;
}
$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 '<p class="alert alert-warning">Please check the the captcha form.</p>';
} else {
$subject = 'Enquiry From Website ' . $_SERVER['HTTP_HOST'];
# Mail Content
$content = "Name: $name\n";
$content .= "Email: $email\n\n";
$content .= "Phone: $phone\n";
$content .= "Message:\n$message\n";
# email headers.
$headers = "From: $name <$email>";
# Send the email.
$success = mail($mail_to, $subject, $content, $headers);
header('Location: thank-you');
if ($success) {
header('Location: thank-you');
} else {
# Set a 500 (internal server error) response code.
http_response_code(500);
echo '<p class="alert alert-warning">Oops! Something went wrong, we couldnt send your message.</p>';
}
}
} else {
# Not a POST request, set a 403 (forbidden) response code.
http_response_code(403);
echo '<p class="alert alert-warning">There was a problem with your submission, please try again.</p>';
}
?>
【问题讨论】:
-
"not working" 不是错误描述,也没有给我们任何继续。请编辑您的问题并向我们详细解释您的问题。怎么了?错误?白页?你做了什么调试?检查错误日志?