设置Recaptcha问题

时间:2017-07-30 16:21:20

标签: php forms recaptcha contact

我真的需要今天完成这件事,这让我很生气。我已按照Google Recaptcha的所有说明进行操作。但是,我没有成功修改原始的php文件,包括验证recaptcha,然后通过电子邮件发送信息。

任何人都可以给我一个关于如何完成这项工作的见解,它是拼图的最后一块!

非常感谢...

<?php
        $msg1 = ''; $succeeded = ''; $failed = ''; $dest = ''; $sender = ''; $enqs = '';
// sort the POST array
ksort($_POST);
// iterate through the POST data and assign them to the email message or variables
foreach ($_POST as $key => $value) {
    if ($key == 'formfail')
    $failed = $value;
    else if ($key == 'formsucc')
    $succeeded = $value;
    else if ($key == 'formdest')
    $dest = $value;
    // add the enquiry types for the subject header
    else if (substr($key,0,3) == 'cb_')
    if (strlen($enqs))
    $enqs .= ', ' . $value;
    else
    $enqs = $value;
    else
    $msg1 .= "$key: $value\n";
    if ($key == 'email')
    $sender = $value;
}
ini_set("sendmail_from", $dest);
$headers  = "From: $dest\r\n";
// send the email
    $sent = mail($dest, "Quote Request From Website: $enqs", $msg1, $headers, '-f' . $dest);
        }if(isset($_POST['g-recaptcha-response'])){
          $captcha=$_POST['g-recaptcha-response'];
        }
        if(!$captcha){
          echo '<h2>Please go back and check the  captcha form.</h2>';
          exit;
        }
        $secretKey = "*********************************************";
        $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) {
        header('Location: thankyou.htm');
exit();
        }
?>

0 个答案:

没有答案