From cc0997f4121a38879136354052d8a3c87a66a2a4 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Sun, 28 Jul 2024 03:47:35 +0200 Subject: [PATCH] Add direct validation function for noda mail checker --- src/NodaMailChecker.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/NodaMailChecker.php b/src/NodaMailChecker.php index 4e55b6f..2f36155 100644 --- a/src/NodaMailChecker.php +++ b/src/NodaMailChecker.php @@ -107,4 +107,26 @@ final class NodaMailChecker { return self::validateMailDomainAccessibilityCached($mysqli, $domain); } + + /** + * Validates mail address, throwing an exception if the mail address is not valid. + * + * @param MDMysqli $mysqli DB connection. + * @param string $mail_address Address. + * + * @return string + */ + public static function validateMail(MDMysqli $mysqli, string $mail_address):string { + + if (empty($mail_address)) return $mail_address; + + $mail_address = MD_STD_IN::sanitize_email($mail_address); + + if (self::validateMailByDomainAccessibilityCached($mysqli, $mail_address) === false) { + throw new MDInvalidEmail("The host name of the entered mail address is invalid"); + } + + return $mail_address; + + } }