Email validation

I’ve got the following script that runs after a form is submitted.
Every part of it works, except one thing.
When I test the form by entering an invalid email address, i get the echo “you have to enter a valid email.”

But when I enter a valid email, it still gives me the same error echo.

What am i missing?


<?php
	
	$to = "myemailaddress@domain.com"; 
	$subject = "Quick Contact Form Submission";
	$firstname_field = $_POST['firstname'];
	$lastname_field = $_POST['lastname'];
	$email_field = $_POST['email'];
	$message_field = $_POST['message'];
	$body = "First: $firstname_field
 Last: $lastname_field
 E-Mail: $email_field
 Message: $message_field
";
	
if(!isset($_POST['submit'])) {
header( "Location: http://www.bluetorchmedia.com/contact.php" );

}elseif (empty($firstname_field) || empty($lastname_field)) {
	echo "you have to fill out everything";
	
	
}elseif (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email_field)) {
  echo "you have to enter a valid email address";

}else{
	
	mail($to, $subject, $body);
?>

<html>
<head>
</head>

<body>
Going to show stuff here.
<?
}
?>
</body>

</html>

So it basically checks to make sure the user got to this script by hitting the submit button on my form.

Then it makes sure certain fields were filled out.

Then it checks if the email is valid, if not then echo the error, if it’s good send the mail() function and display the html.

If the email is valid it still shows the error echo only.

Please help.