# Block Email Domains in WPForms

> Shows an error when an email address from a domain on your block list, such as throwaway inbox services, is entered in any WPForms email field.

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

## Code

```php
$wpide_wpf_blocked_domains = array( 'mailinator.com', 'yopmail.com', 'tempmail.com', 'guerrillamail.com', 'sharklasers.com' );

add_action( 'wpforms_process_validate_email', function ( $field_id, $field_submit, $form_data ) use ( $wpide_wpf_blocked_domains ) {
    $email  = strtolower( trim( is_array( $field_submit ) ? (string) reset( $field_submit ) : (string) $field_submit ) );
    $domain = (string) substr( strrchr( $email, '@' ), 1 );

    foreach ( $wpide_wpf_blocked_domains as $blocked ) {
        if ( $domain && ( $domain === $blocked || substr( $domain, -strlen( '.' . $blocked ) ) === '.' . $blocked ) ) {
            $process = method_exists( wpforms(), 'obj' ) ? wpforms()->obj( 'process' ) : wpforms()->process;
            $process->errors[ $form_data['id'] ][ $field_id ] = 'Please use a different email address.';
            return;
        }
    }
}, 10, 3 );
```

## Notes

Subdomains of listed domains are blocked too; add domains as spam arrives.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Block Email Domains 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/
