diff --git a/index.php b/index.php index a13fe0e..c38923f 100644 --- a/index.php +++ b/index.php @@ -306,7 +306,7 @@
- +
@@ -352,9 +352,39 @@ const formData = new FormData(form); const messageDiv = document.getElementById('form-message'); const rightColumn = document.getElementById('right-column-content'); + const emailInput = form.querySelector('input[name="email"]'); + const emailValue = (emailInput.value || '').trim().toLowerCase(); + const blockedDomains = new Set([ + '10minutemail.com', + 'dispostable.com', + 'emailondeck.com', + 'fakeinbox.com', + 'guerrillamail.com', + 'maildrop.cc', + 'mailinator.com', + 'mailnesia.com', + 'mintemail.com', + 'sharklasers.com', + 'tempmail.com', + 'temp-mail.org', + 'trashmail.com', + 'yopmail.com', + 'example.com', + 'example.net', + 'example.org' + ]); messageDiv.textContent = ''; // Clear previous messages + if (emailValue && emailValue.includes('@')) { + const emailDomain = emailValue.split('@').pop(); + if (blockedDomains.has(emailDomain)) { + messageDiv.textContent = 'Please use your real email address. Temporary or disposable inboxes are not allowed.'; + emailInput.focus(); + return; + } + } + fetch('register.php', { method: 'POST', body: formData diff --git a/register.php b/register.php index afbbe54..fe380f9 100644 --- a/register.php +++ b/register.php @@ -5,6 +5,75 @@ require_once 'mail/MailService.php'; header('Content-Type: application/json'); +function normalize_email_address($email) { + return strtolower(trim((string) $email)); +} + +function has_valid_email_dns($domain) { + if ($domain === '') { + return false; + } + + return checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A') || checkdnsrr($domain, 'AAAA'); +} + +function is_disposable_email_domain($domain) { + static $blocked_domains = [ + '10minutemail.com', + 'dispostable.com', + 'emailondeck.com', + 'fakeinbox.com', + 'guerrillamail.com', + 'maildrop.cc', + 'mailinator.com', + 'mailnesia.com', + 'mintemail.com', + 'sharklasers.com', + 'tempmail.com', + 'temp-mail.org', + 'trashmail.com', + 'yopmail.com', + 'example.com', + 'example.net', + 'example.org', + ]; + + return in_array($domain, $blocked_domains, true); +} + +function validate_registration_email($email) { + $email = normalize_email_address($email); + + if ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) { + return 'Please enter a valid email address.'; + } + + if (strlen($email) > 190) { + return 'Please enter a shorter email address.'; + } + + $parts = explode('@', $email); + if (count($parts) !== 2) { + return 'Please enter a valid email address.'; + } + + [$local, $domain] = $parts; + + if ($local === '' || $domain === '') { + return 'Please enter a valid email address.'; + } + + if (is_disposable_email_domain($domain)) { + return 'Please use your real email address. Temporary or disposable inboxes are not allowed.'; + } + + if (!has_valid_email_dns($domain)) { + return 'Please use an email with a real mail domain.'; + } + + return null; +} + // --- Helper function to fetch webinar details --- function get_webinar_details($id) { if (empty($id)) return null; @@ -34,7 +103,9 @@ if (!$webinar) { } // --- DATA CAPTURE --- -$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); +$email_input = (string) filter_input(INPUT_POST, 'email', FILTER_UNSAFE_RAW); +$email = normalize_email_address($email_input); +$email_error = validate_registration_email($email); $first_name = filter_input(INPUT_POST, 'first_name', FILTER_SANITIZE_STRING); $last_name = filter_input(INPUT_POST, 'last_name', FILTER_SANITIZE_STRING); $company = filter_input(INPUT_POST, 'company', FILTER_SANITIZE_STRING); @@ -53,11 +124,16 @@ $allowed_sources = [ ]; // --- VALIDATION --- -if (!$first_name || !$last_name || !$email || $how_did_you_hear === '') { +if (!$first_name || !$last_name || $email === '' || $how_did_you_hear === '') { echo json_encode(['success' => false, 'error' => 'Please fill out all required fields.']); exit; } +if ($email_error !== null) { + echo json_encode(['success' => false, 'error' => $email_error]); + exit; +} + if (!in_array($how_did_you_hear, $allowed_sources, true)) { echo json_encode(['success' => false, 'error' => 'Please choose how you heard about this webinar from the list.']); exit;