订阅按钮的隐形ReCaptcha

时间:2018-05-31 03:27:41

标签: php html forms recaptcha invisible-recaptcha

我在网站底部有一个简单的简报注册(www.valleygolfwillmar.com)。我一直在收集大量的垃圾邮件机器人电子邮件地址,所以决定添加Invisible ReCaptcha以帮助减少非用户子网站。

一切似乎都运行正常,电子邮件地址被添加到.TXT文件中,除非您单击订阅时打开用于编写保存所有电子邮件地址的txt文件的php脚本。

在重新加入recaptcha之前,它会弹出一条消息,说“已订阅!谢谢!”。如何使用隐形ReCaptcha重新开始这项工作?

以下是简报代码:

<!-- Newsletter Form -->
<h4 class="letter-spacing-1">Join Our Newsletter</h4>
    <p>Subscribe to Our Newsletter to get info on Upcoming Events &amp; Offers</p>

    <form  id="newsletter" class="validate" action="php/newsletter.php" 
           method="post" data-success="Subscribed! Thank you!" 
           data-toastr-position="bottom-right">
        <div class="input-group">
            <span class="input-group-addon"><i class="fa fa-envelope"></i></span>
            <input type="email" id="email" name="email" 
                   class="form-control required" placeholder="Enter your Email">
            <span class="input-group-btn">
                <button class="btn btn-success g-recaptcha" 
                        data-badge="inline" 
                        data-sitekey="6LdIn1gUAAAAAB7ds1fYb2awLLPBKz1Z5d4qm23e" 
                        data-callback="onSubmit" type="submit">Subscribe
                </button>
            </span>
        </div>
    </form>

    <style>
        .grecaptcha-badge {display: none;}
    </style>

    <script src='https://www.google.com/recaptcha/api.js'></script>
    <script>
        function onSubmit(token) {
            document.getElementById("newsletter").submit();
        }
    </script>
<!-- /Newsletter Form -->

以下是我一直使用的简报的PHP代码:

<?php
/**
 * @version     v1.0.0
 * @author      
 * @date        Saturday, April 9, 2016
**/ 
date_default_timezone_set('Etc/UTC');
@ini_set('display_errors', 0);
@ini_set('track_errors', 0);

$array['email'] = isset($_REQUEST['email']) ? ckmail($_REQUEST['email']) : false;

if($array['email'] !== false) {

    $fh = fopen('_newsletter.txt', 'a+');
    fwrite($fh, "\r\n" . $array['email']);
    fclose($fh);

    unset($fh, $array);
}

/************************************ 
 @CHECK EMAIL
/************************************/
function ckmail($email) {
    $email = trim(strtolower($email));
    if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/',trim($email))){
        return $email;
    } else { 
        return false; 
    }
}
?>

0 个答案:

没有答案