How can PHP be used to differentiate between a valid email address syntax and an actual existing email address?

To differentiate between a valid email address syntax and an actual existing email address in PHP, you can use the filter_var function with the FILTER_VALIDATE_EMAIL filter to check the syntax of the email address. To verify if the email address actually exists, you can use a library like PHPMailer to send a verification email and check for a successful delivery response.

$email = "example@example.com";

// Check email address syntax
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Email address syntax is valid
    // Send a verification email to check if it exists
    // Example using PHPMailer library
    require 'PHPMailer/PHPMailer.php';
    $mail = new PHPMailer\PHPMailer\PHPMailer();
    $mail->setFrom('your@example.com', 'Your Name');
    $mail->addAddress($email);
    $mail->Subject = 'Verification Email';
    $mail->Body = 'This is a verification email to check if the email address exists.';
    
    if ($mail->send()) {
        echo "Email address exists.";
    } else {
        echo "Email address does not exist.";
    }
} else {
    echo "Invalid email address syntax.";
}