This is where to use it, note the comment saying it can replace your 'if' statement.
PHP Code:
<?php
$to = "";
$subject = "subject";
$mail = $_POST['mail'];
$result = preg_split('/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i', $mail);
if ($result){
if ($mail = $_POST['mail']) { /*Why this line it will always be true, you can replace it with the 'if' above*/
$body = "E-Mail: $mail";
echo "success";
mail($to, $subject, $body, "From: $mail");
} else {
echo "error";
}
?>
If you are submitting the email from an HTML form then personally I prefer to do any validation at the input stage.
It is fairly easy to use javascript to field validate a form
Bookmarks