Fix email validation

Replace preg_match() with filter_var() for more accurate and reliable email validation.
This commit is contained in:
Eric Fawcett 2017-10-17 13:20:55 -04:00 committed by GitHub
parent 6a8bb1e9da
commit 288501be64
1 changed files with 3 additions and 8 deletions

View File

@ -2,7 +2,7 @@
/************************************************************************ /************************************************************************
* SendForm Version 0.99.1 * * SendForm Version 0.99.1 *
* Created 10 May 2005 * * Created 10 May 2005 *
* Modified 12 Oct 2017 * * Modified 17 Oct 2017 *
* Questions/Comments: eric.fawcett@gmail.com * * Questions/Comments: eric.fawcett@gmail.com *
* * * *
* COPYRIGHT NOTICE * * COPYRIGHT NOTICE *
@ -228,7 +228,7 @@
badreferer($theDomain); badreferer($theDomain);
} }
function errormail($errormsg) { 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() { function fillrecipients() {
global $recipients; global $recipients;
@ -284,12 +284,7 @@
#return $matches[0]; #return $matches[0];
} }
function validemail($email) { function validemail($email) {
// define a regular expression for "normal" addresses if (filter_var($email, FILTER_VALIDATE_EMAIL)) return true;
$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;
else return false; else return false;
} }
function writeStyles() { function writeStyles() {