Block Email Domains in Fluent Forms
Shows an error when someone uses an email address from a domain on your block list, such as throwaway inbox services, in a Fluent Forms form.
Opens WPIDE on
Code
$wpide_ff_email_fields = array( 'email' ); // Email field names to check.
$wpide_ff_blocked_domains = array( 'mailinator.com', 'yopmail.com', 'tempmail.com', 'guerrillamail.com', 'sharklasers.com' );
add_filter( 'fluentform/validation_errors', function ( $errors, $data, $form, $fields ) use ( $wpide_ff_email_fields, $wpide_ff_blocked_domains ) {
foreach ( $wpide_ff_email_fields as $name ) {
if ( empty( $data[ $name ] ) || ! is_string( $data[ $name ] ) ) {
continue;
}
$domain = strtolower( (string) substr( strrchr( trim( $data[ $name ] ), '@' ), 1 ) );
foreach ( $wpide_ff_blocked_domains as $blocked ) {
if ( $domain && ( $domain === $blocked || substr( $domain, -strlen( '.' . $blocked ) ) === '.' . $blocked ) ) {
$errors[ $name ] = array( 'Please use a different email address.' );
break;
}
}
}
return $errors;
}, 10, 4 );
Notes
Needs Fluent Forms 5.0 or later and checks the field named "email" unless you list other email field names at the top.
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.