How can one check the syntax and ownership of entered email addresses in PHP?

To check the syntax and ownership of entered email addresses in PHP, you can use a combination of regular expressions to validate the email format and then verify the domain ownership by performing a DNS lookup. This can help ensure that the email address is correctly formatted and corresponds to a valid domain.

$email = "example@example.com";

// Check email syntax
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Invalid email address format";
} else {
    // Extract domain from email address
    $domain = explode('@', $email)[1];
    
    // Check domain ownership
    if (checkdnsrr($domain, 'MX')) {
        echo "Email address is valid";
    } else {
        echo "Domain does not exist";
    }
}