How to Block Email Addresses From Your Forms

Overview

Would you like to block email addresses from your forms? You may have identified specific email addresses as spammers and want to stop those entries from being saved. Using a small PHP snippet you can easily block these email addresses from your site.

Setup

To restrict specific email addresses, copy the code shown below to your site.

/*
 * Blacklist emails from your WPForms.
 *
 * @link https://wpforms.com/developers/how-to-block-email-addresses-from-your-forms/
 *
*/

function wpf_dev_blacklist( $honeypot, $fields, $entry, $form_data ) {

  	// Use the email as the key. The value will be used in the log
	$blacklist = array(
		'123test@me.com' => 'Ima Believer',
		'me@me.com' => 'Me Me'
	);
	
	foreach( $form_data['fields'] as $id => $field ) {
		if( 'email' == $field['type'] && array_key_exists( $entry['fields'][$id], $blacklist ) )
			$honeypot = '[Blacklist] ' . $blacklist[$entry['fields'][$id]];
	}
	
	return $honeypot;
}
add_filter( 'wpforms_process_honeypot', 'wpf_dev_blacklist', 10, 4 );

You can add as many email addresses as you’d like to this list separating them with a comma.

When a user tries to complete any of your forms with that email, the entry will not be saved to the Entries page of the form.

Now you've successfully blacklisted the email address

And that’s all you need to blacklist a specific email address. Would you like to create a whitelist of accepted email domains? Take a look at our tutorial on How to Restrict Email Domains.