Block Disposable Emails in Mailchimp for WP Forms
Refuses newsletter signups from throwaway email domains in Mailchimp for WordPress forms, keeping your audience clean and your Mailchimp bill lower.
Opens WPIDE on
Code
$wpide_blocked = array( 'mailinator.com', 'yopmail.com', '10minutemail.com', 'guerrillamail.com', 'tempmail.com', 'trashmail.com', 'getnada.com' );
$wpide_message = 'Please use a permanent email address.';
add_filter( 'mc4wp_form_errors', function ( $errors, $form ) use ( $wpide_blocked ) {
$data = is_object( $form ) && isset( $form->data ) ? (array) $form->data : array();
$email = isset( $data['EMAIL'] ) ? strtolower( (string) $data['EMAIL'] ) : '';
$domain = substr( (string) strrchr( $email, '@' ), 1 );
if ( $domain && in_array( $domain, $wpide_blocked, true ) ) {
$errors[] = 'wpide_disposable_email';
}
return $errors;
}, 10, 2 );
add_filter( 'mc4wp_form_messages', function ( $messages ) use ( $wpide_message ) {
$messages['wpide_disposable_email'] = $wpide_message;
return $messages;
} );
Notes
Add domains to $wpide_blocked. The error text can be changed in $wpide_message.
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.