validating email before insert into

So I have tried rewriting this several different ways and I give up. Well I will keep trying until some smart person sets me straight. My code keeps giving me an error - undefined variable - email. So here is what I have.

if (!empty($_POST[‘EMail’])) {
$email = mysql_real_escape_string(trim($_POST[‘EMail’]));

    if (filter_var($email, FILTER_VALIDATE_EMAIL)) {            
        $email = $email;
    } else {
        $errors[] = "Please enter a valid e-mail address.";
    }
}else{
    $errors = "You did not enter your e-mail address.";
}

It just means that php is finding an instance of $email before its being used. If you’re using it outside of the sending script, just add if(isset($email()) to it and it’ll get rid of the error. Error messages should be off on a live server anyways, so it shouldn’t be showing it.

Sponsor our Newsletter | Privacy Policy | Terms of Service