What are some common pitfalls when using PHP to validate email addresses in a form?

One common pitfall when using PHP to validate email addresses in a form is not properly checking if the email address is in a valid format. To solve this issue, you can use PHP's built-in filter_var function with the FILTER_VALIDATE_EMAIL filter to validate the email address.

$email = $_POST['email'];

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