What are the potential pitfalls of using preg_match for email validation in PHP?

Using preg_match for email validation in PHP may not cover all edge cases and variations of valid email addresses. It is better to use PHP's built-in filter_var function with the FILTER_VALIDATE_EMAIL flag for more accurate validation.

$email = "test@example.com";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Valid email address";
} else {
    echo "Invalid email address";
}