What are some recommended methods for checking the validity of email addresses in PHP, beyond basic syntax validation?

Validating email addresses in PHP beyond basic syntax validation can involve checking the domain's MX records, sending a verification email, or using third-party services like Mailgun or NeverBounce to verify the email address's deliverability.

// Example code snippet using a third-party service like Mailgun to verify email address validity

$email = 'test@example.com';
$api_key = 'your_mailgun_api_key';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v3/address/validate?address=' . urlencode($email));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, 'api:' . $api_key);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);

if ($result['is_valid']) {
    echo 'Email address is valid';
} else {
    echo 'Email address is invalid';
}