You're sending mail outside the if (isset($_POST['submitted']))
block. I think the problem is that you have an extra close brace here:
//Check for a valid email
if (!filter_var($_REQUEST['email'], FILTER_VALIDATE_EMAIL)) {
$errors[] = 'The email provided is not valid.';
} // <<===== HERE
} else {
$email = $_REQUEST['email'];
}
As a result, the else
clause isn't connected to the email validation, it's connected to if (isset($_POST['submitted']))
. So when the form hasn't been submitted, you set $email
and then you go into the code that sends email.