if (empty($email)) echo json_encode(['valid' => false, 'message' => 'Email is required']); exit;
?> <?php function validateEmailAdvanced($email) // 1. Check format if (!filter_var($email, FILTER_VALIDATE_EMAIL)) return false; // 2. Extract domain $domain = substr(strrchr($email, "@"), 1); check email valid php
foreach ($testEmails as $email) $result = EmailValidator::validate($email, true, true); if ($result['valid']) echo "✓ $email is valid\n"; else echo "✗ $email is invalid: $result['error']\n"; if (empty($email)) echo json_encode(['valid' =>
if (empty($email)) $error = 'Email is required'; elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) $error = 'Please enter a valid email address'; elseif (!checkdnsrr(substr(strrchr($email, "@"), 1), 'MX')) $error = 'Email domain does not exist'; else $success = 'Valid email address!'; 'Email is required'])
// Usage examples $testEmails = [ 'user@example.com', 'invalid-email', 'user@gmail.com', 'user@mailinator.com' ];
<?php if ($error): ?> <p style="color: red;"><?php echo $error; ?></p> <?php endif; ?> <?php if ($success): ?> <p style="color: green;"><?php echo $success; ?></p> <?php endif; ?> <button type="submit">Validate Email</button> </form> </body> </html> <?php // validate-ajax.php header('Content-Type: application/json'); $email = $_GET['email'] ?? '';