What best practices should be followed when handling user input, especially email addresses, in PHP applications?

When handling user input, especially email addresses, in PHP applications, it is important to validate and sanitize the input to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. One way to validate email addresses is by using PHP's built-in filter_var function with the FILTER_VALIDATE_EMAIL filter.

$email = $_POST['email'];

// Validate email address
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Email address is valid, proceed with processing
} else {
    // Invalid email address, handle error
}