添加recaptcha代码后,我的联系表单不会重定向

时间:2017-12-22 21:56:20

标签: php

尝试将recaptcha添加到我的联系表单中。我无法将联系表单重定向到感谢页面。表单确实正确发送电子邮件。

<?php
if(isset($_POST['g-recaptcha-response'])){
    $captcha=$_POST['g-recaptcha-response'];
}

if(!$captcha){
    echo '<h2>Please check the the captcha form.</h2>';
    exit;
}

$secretKey = "my key";
$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 'You are spammer';
} else {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $phone = $_POST['phone'];
    $formcontent="From: $name \n Message: $message \n Email:$email \n Phone:$phone";
    $recipient = "example@example.com";
    $subject = "Website Contact Form";
    $mailheader = "From: $email \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    header('Location:https://www.example.com/thank-you.html');
    exit();
}

?>

表单代码:按要求添加网站表单代码

<div class="col-md-4">
<form id="quote-form" action="inc/sendmail.php" method="post">
<div class="sec-title text-center">
<h1>Request for Quote</h1>
<span class="border center"></span>
</div>
<div class="row">
<div class="col-md-12">
<input type="text" name="name" value="" placeholder="Your Name*" required="">
 <input type="email" name="email" value="" placeholder="Your Mail*" required="">
 <input type="text" name="phone" value="" placeholder="Your Phone*" required="">
 <select class="selectmenu" name=message>
 <option selected="selected">Select Service</option>
 <option value="Need Quote on a prod 1</option>
 <option value="Need Quote on a prod 2</option>
 <option>Other</option>
 </select>
 <div class="g-recaptcha" data-sitekey="sitekeygoeshere-removed-forposting"></div>
 <button class="thm-btn bg-clr1" name="submit" type="submit">Get a Quote</button>
 </div>  
 </div>    
 </form>    
 </div>

我删除了代码中的网站密钥。

0 个答案:

没有答案