# Require a Business Email in Contact Form 7

> Asks visitors to use their work email instead of a free webmail address such as Gmail or Yahoo, which helps B2B sites get qualified leads.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: contact-form-7, validation, leads
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/cf7-business-email-only/

## Code

```php
$wpide_cf7_free_providers = array( 'gmail.com', 'googlemail.com', 'yahoo.com', 'hotmail.com', 'outlook.com', 'live.com', 'aol.com', 'icloud.com', 'gmx.com', 'proton.me', 'protonmail.com', 'mail.com', 'yandex.com' );
$wpide_cf7_business_fields = array(); // Field names to check, e.g. array( 'work-email' ). Empty = all email fields.

$wpide_cf7_business_check = function ( $result, $tag ) use ( $wpide_cf7_free_providers, $wpide_cf7_business_fields ) {
    if ( $wpide_cf7_business_fields && ! in_array( $tag->name, $wpide_cf7_business_fields, true ) ) {
        return $result;
    }

    $email  = isset( $_POST[ $tag->name ] ) ? strtolower( sanitize_email( wp_unslash( $_POST[ $tag->name ] ) ) ) : '';
    $domain = (string) substr( strrchr( $email, '@' ), 1 );

    if ( $domain && in_array( $domain, $wpide_cf7_free_providers, true ) ) {
        $result->invalidate( $tag, 'Please use your work email address.' );
    }

    return $result;
};

add_filter( 'wpcf7_validate_email', $wpide_cf7_business_check, 20, 2 );
add_filter( 'wpcf7_validate_email*', $wpide_cf7_business_check, 20, 2 );
```

## Notes

Limit it to certain fields by adding their names to the list at the top; leave the list empty to check every email field.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Require a Business Email in Contact Form 7" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
