What are the best practices for handling form validation errors in PHP, especially related to email format validation?

When handling form validation errors in PHP, especially related to email format validation, it is important to check if the email input is in a valid format using PHP's filter_var function with the FILTER_VALIDATE_EMAIL filter. If the email is not in a valid format, an error message should be displayed to the user.

$email = $_POST['email'];

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    $errors[] = "Invalid email format";
}