联系人表格7中的无封锁电子邮件域

问题描述 投票:1回答:1

我想从联系表7中阻止一般的电子邮件ID帐户。我在function.php文件中添加了以下代码,但它不起作用。

我正在使用wordpress 4.6.1,请联系表格7版本4.6和21个主题。请帮助我解决此问题。

function blocked_email_domain($email) {
$blocked = array("@gmail.com", "@hotmail.com", "@yahoo.com", "@yahoo.in","@msn.com", "@live.com", "@outlook.com", "@microsoft.com", "@zoho.com", "@rediff.com");
$email = strstr($email, '@');
if(in_array($email, $blocked))
    return false;
else
    return true;
}

    function custom_email_validation_filter($result, $tag) {
    $type = $tag['type'];
    $name = $tag['name'];
    if($name == 'your-email') { // Only apply to fields with the form field name of "your-email"
    $the_value = $_POST[$name];
    if(!blocked_email_domain($the_value)){
    $result['valid'] = false;
    $result->invalidate( $tag, 'You need to provide an email address that isn\'t hosted by a free provider.<br />Please contact us directly if this isn\'t possible.');

    };
    };
    return $result;
    }
    add_filter('wpcf7_validate_email','custom_email_validation_filter', 10, 2); // Email field
    add_filter('wpcf7_validate_email*', 'custom_email_validation_filter', 10, 2); // Required Email field
wordpress contact-form-7
1个回答
0
投票

这里是易于使用的插件,可轻松用于多个字段和表单。

联系表7 –不需要的黑名单电子邮件->https://wordpress.org/plugins/block-email-cf7/

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.