Created
July 11, 2025 12:55
-
-
Save wpeasy/f7917fdbd3329cda8d9ce7f27c4de617 to your computer and use it in GitHub Desktop.
Gravity Block Disposable email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter('gform_field_validation', 'check_disposable_email_gf', 10, 4); | |
| function check_disposable_email_gf($result, $value, $form, $field) { | |
| if ($field->get_input_type() !== 'email' || empty($value)) { | |
| return $result; | |
| } | |
| // Exact domain blocklist | |
| $blocked_domains = [ | |
| 'emailnow.net', | |
| 'tempmail.net', | |
| '10minutemail.com', | |
| 'mailinator.com', | |
| 'guerrillamail.com', | |
| 'trashmail.com', | |
| 'fakeinbox.com', | |
| 'maildrop.cc', | |
| 'getnada.com', | |
| 'dispostable.com', | |
| 'yopmail.com', | |
| ]; | |
| // Partial MX host blocklist (substring match) | |
| $blocked_mx_substrings = [ | |
| 'anonymmail.net', | |
| 'emailnow.net', | |
| ]; | |
| // Get domain from email | |
| $domain = strtolower(substr(strrchr($value, "@"), 1)); | |
| // Block if domain is exactly in the list | |
| if (in_array($domain, $blocked_domains)) { | |
| $result['is_valid'] = false; | |
| $result['message'] = 'Sorry, we do not accept temporary email addresses.'; | |
| return $result; | |
| } | |
| // Check MX records for partial match | |
| $mx_records = dns_get_record($domain, DNS_MX); | |
| foreach ($mx_records as $record) { | |
| if (isset($record['target'])) { | |
| foreach ($blocked_mx_substrings as $blocked_mx) { | |
| if (stripos($record['target'], $blocked_mx) !== false) { | |
| $result['is_valid'] = false; | |
| $result['message'] = 'Sorry, we do not accept email addresses from disposable services.'; | |
| return $result; | |
| } | |
| } | |
| } | |
| } | |
| return $result; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment