What are the potential consequences of not validating email addresses in a PHP contact form?

If email addresses are not validated in a PHP contact form, it can lead to spam submissions, incorrect data being entered, and potential security vulnerabilities. To solve this issue, you can implement email validation using PHP's built-in filter_var function with the FILTER_VALIDATE_EMAIL filter.

$email = $_POST['email'];

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Invalid email address, handle error
} else {
    // Valid email address, continue processing form data
}