What are the best practices for handling email address validation in PHP, considering the use of special characters and international domains?

When validating email addresses in PHP, it is important to use a regular expression that allows for special characters and international domain names. This can be achieved by using the FILTER_VALIDATE_EMAIL filter along with the FILTER_FLAG_EMAIL_UNICODE flag. Additionally, it is recommended to sanitize user input before validating the email address to prevent any potential security vulnerabilities.

$email = "user@example.com";

if (filter_var($email, FILTER_VALIDATE_EMAIL, FILTER_FLAG_EMAIL_UNICODE)) {
    echo "Email address is valid.";
} else {
    echo "Email address is not valid.";
}