From 288501be642a4b2a9b38db3c26b24db9b1ea8a0e Mon Sep 17 00:00:00 2001 From: eekdood Date: Tue, 17 Oct 2017 13:20:55 -0400 Subject: [PATCH] Fix email validation Replace preg_match() with filter_var() for more accurate and reliable email validation. --- sendform.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/sendform.php b/sendform.php index 052fc50..64098f6 100644 --- a/sendform.php +++ b/sendform.php @@ -2,7 +2,7 @@ /************************************************************************ * SendForm Version 0.99.1 * * Created 10 May 2005 * - * Modified 12 Oct 2017 * + * Modified 17 Oct 2017 * * Questions/Comments: eric.fawcett@gmail.com * * * * COPYRIGHT NOTICE * @@ -228,7 +228,7 @@ badreferer($theDomain); } function errormail($errormsg) { - if (validemail($errorTo)) mail($errorTo, 'Error on Accu-Trim Form', $errormsg, $headers); + if (validemail($errorTo)) mail($errorTo, 'Error on form', $errormsg, $headers); } function fillrecipients() { global $recipients; @@ -284,12 +284,7 @@ #return $matches[0]; } function validemail($email) { - // define a regular expression for "normal" addresses - $normal = "^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$"; - // define a regular expression for "strange looking" but syntactically valid addresses - $validButRare = "^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$"; - if (preg_match($normal, $email)) return true; - else if (preg_match($validButRare, $email)) return true; + if (filter_var($email, FILTER_VALIDATE_EMAIL)) return true; else return false; } function writeStyles() {