Block Email Domains in Fluent Forms: 2 Easy PHP Snippets

block email domains in fluent forms

Quick answer: To block email domains in Fluent Forms, hook into fluentform/validate_input_item_input_email, read the domain after the @ sign and return an error message when it is on your blocked list. The two snippets below work on all forms or only on the forms you choose.

Block email domains in Fluent Forms

Why block email domains in Fluent Forms?

  • Stop spam bots that use disposable addresses such as mailinator.com.
  • Make B2B or quote forms accept only company emails (no Gmail or Yahoo).
  • Block a specific person or address that keeps sending junk.

Fluent Forms validates every email field through a filter (see the Fluent Forms developer docs), so you can reject an address before the entry is saved and show your own error message.

Snippet 1: apply to all forms

Add this to your child theme functions.php or a code snippets plugin, then change the domains and message.

functions.php
/**
 * Fluent Forms: block email domains and addresses (all forms).
 */
add_filter( 'fluentform/validate_input_item_input_email', function ( $error, $field, $formData, $fields, $form ) {
	$blocked_domains = array( 'mailinator.com', 'tempmail.com', 'test.com' ); // change these
	$blocked_emails  = array( 'spam@example.com' );                         // exact addresses (optional)
	$message         = 'Please use your business email address.';

	$name  = $field['name'];
	$email = isset( $formData[ $name ] ) ? strtolower( trim( $formData[ $name ] ) ) : '';
	if ( '' === $email || false === strpos( $email, '@' ) ) {
		return $error;
	}

	$domain = substr( strrchr( $email, '@' ), 1 );
	if ( in_array( $domain, $blocked_domains, true ) || in_array( $email, $blocked_emails, true ) ) {
		return array( $message );
	}
	return $error;
}, 10, 5 );

Snippet 2: block domains on selected forms only

Use this if only your quote or B2B form should reject free email providers. Find the form ID in Fluent Forms > All Forms.

functions.php
/**
 * Fluent Forms: block email domains on specific forms only.
 */
add_filter( 'fluentform/validate_input_item_input_email', function ( $error, $field, $formData, $fields, $form ) {
	$form_ids        = array( 12, 15 );                       // your form IDs
	$blocked_domains = array( 'gmail.com', 'yahoo.com', 'hotmail.com' );
	$message         = 'Please use your company email address.';

	if ( ! in_array( (int) $form->id, $form_ids, true ) ) {
		return $error;
	}

	$name  = $field['name'];
	$email = isset( $formData[ $name ] ) ? strtolower( trim( $formData[ $name ] ) ) : '';
	$domain = $email ? substr( strrchr( $email, '@' ), 1 ) : '';

	if ( $domain && in_array( $domain, $blocked_domains, true ) ) {
		return array( $message );
	}
	return $error;
}, 10, 5 );

How the code works

  • The filter runs for every email field when the form is submitted.
  • The email is trimmed and lower-cased, so Test@Mailinator.COM is caught too.
  • The part after @ is compared with your blocked list.
  • Returning an array with a message stops the submission and shows that message under the field.

Troubleshooting

  • Nothing happens on an older Fluent Forms version: before version 5, the hook was named fluentform_validate_input_item_input_email (underscore instead of slash). Use that name instead.
  • Subdomains still get through: add them to the list, for example mail.example.com.
  • Error shows on every email: make sure the domains in the array are lower-case and have no spaces.

Frequently asked questions

Can Fluent Forms block email domains without code?

Fluent Forms Pro has some validation options, but blocking a custom list of domains is easiest with the small PHP snippet above.

How do I block Gmail in Fluent Forms?

Add gmail.com to the blocked domains array in either snippet. Snippet 2 lets you do it only on the forms where you need company emails.

Will this stop all spam?

It stops sign-ups from the domains you list. Combine it with Fluent Forms’ built-in reCAPTCHA or Turnstile for bots.

Need help with forms, spam or WordPress customisation? Get a free quote.

Need help with your own site? Get a free quote or see my recent builds.

Tanvir Hossain Tofan, WordPress developer

Written by Tanvir Hossain Tofan

WordPress & Shopify developer from Bangladesh with 5+ years of experience building custom ACF themes, Elementor sites, plugins and Shopify stores for clients worldwide. Author of the Toofan Stage-to-Live Sync and Talkvara AI Chatbot plugins on WordPress.org.

See my work · Hire me · WhatsApp · YouTube · LinkedIn

Previous Post

Create a WordPress Admin User via functions.php or WP-CLI (Safe Method)

Quick answer: To create a WordPress admin user whe ...

Next Post

Add Custom Post Type to Search Results and Filter by ACF Field (2 Ways)

Add custom post types to WordPress search results ...

If you find it useful

Buy me a coffee

ACF

Blog

Elementor

HTML JQuery

PHP

Tips & Tricks

WordPress

WordPress Maintenance Checklist: Weekly, Monthly and Yearly Tasks

The WordPress maintenance routine I use for client ...

Create a WordPress Admin User via functions.php or WP-CLI (Safe Method)

Quick answer: To create a WordPress admin user whe ...

bKash Payment Gateway in WooCommerce: How to Add bKash, Nagad and Cards

How to add a bKash payment gateway to WooCommerce: ...

Steadfast Courier WooCommerce Integration: Book Parcels From Your Orders Page

How to connect Steadfast courier to WooCommerce: o ...

AI Agent for WordPress: What It Can Do and How to Add One to Your Site

What an AI agent for WordPress can really do, the ...

Back to top