# Require a Work Email in WPForms

> Asks for a company email address instead of Gmail, Yahoo or other free webmail in WPForms email fields, so B2B forms collect qualified leads.

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

## Code

```php
$wpide_wpf_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_wpf_business_forms = array(); // Form IDs; empty = all forms.

add_action( 'wpforms_process_validate_email', function ( $field_id, $field_submit, $form_data ) use ( $wpide_wpf_free_providers, $wpide_wpf_business_forms ) {
    if ( $wpide_wpf_business_forms && ! in_array( (int) $form_data['id'], array_map( 'intval', $wpide_wpf_business_forms ), true ) ) {
        return;
    }

    $email  = strtolower( trim( is_array( $field_submit ) ? (string) reset( $field_submit ) : (string) $field_submit ) );
    $domain = (string) substr( strrchr( $email, '@' ), 1 );

    if ( $domain && in_array( $domain, $wpide_wpf_free_providers, true ) ) {
        $process = method_exists( wpforms(), 'obj' ) ? wpforms()->obj( 'process' ) : wpforms()->process;
        $process->errors[ $form_data['id'] ][ $field_id ] = 'Please use your work email address.';
    }
}, 10, 3 );
```

## Notes

Limit it to specific forms with the list of form IDs at the top; empty checks every form.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Require a Work Email in WPForms" 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/
