Are there any best practices for handling email validation in PHP registration forms?

When handling email validation in PHP registration forms, it is important to ensure that the email provided by the user is in a valid format. One common way to do this is by using PHP's built-in filter_var function with the FILTER_VALIDATE_EMAIL filter. This function will check if the email address is in a valid format according to RFC 822.

$email = $_POST['email'];

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