Block Email Addresses or Email Domains

Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

Would you like to block certain email addresses or email domains 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 or domains, copy the code shown below and place it into the PHP Scripts -> Form Process area of your form.

// You can add as many email addresses as you'd like to this list.
$blacklist = [
    '@domain1.com',
    '@domain2.com',
    '[email protected]'
];

// The name of the field representing the email address input
$field_name = 'email';

// The error message to show when an invalid email address is submitted
$error_message = 'This email is not allowed';

// Do not edit below
foreach ($blacklist as $blacklist_email)
{
    if (stripos($post[$field_name], $blacklist_email) !== false)
    {
        throw new Exception($error_message);
    }
}

Remember to update the $blacklist array with the email addresses and domains you want in your black list.

Last updated on Nov 26th 2024 12:11