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.
Opens WPIDE on
Code
$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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.