Untitled

 avatar
unknown
php
2 years ago
1.1 kB
5
Indexable
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 == 'BusinessEmail') { // Only apply to fields with the form field name of "your-email"
    $the_value = $_POST[$name];
        if(!blocked_email_domain($the_value)){
            $result->invalidate( $tag, __('You need to provide an email address that isn\'t hosted by a free provider. Please contact us directly if this isn\'t possible.', 'adaptive'));   
        };
    };
    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
Editor is loading...