To validate an email in PHP, use PHP's built in filters. See here for full details:
Taken from the above URL, here's an example of how to validate an email:
if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
echo "This ($email_a) email address is considered valid.";
}
Applied to your code, this would make your valid_email()
function the following:
function valid_email($address)
return filter_var($address, FILTER_VALIDATE_EMAIL);
}