masroore / verifyemail
Provides means for verification of e-mail addresses.
Requires
- php: ^7.1.3
- psr/log: ^1.1
- symfony/cache: ^4.2
- symfony/polyfill-intl-idn: ^1.11
- symfony/polyfill-mbstring: ^1.11
Suggests
- ext-intl: For best performance
- ext-mbstring: For best performance
This package is auto-updated.
Last update: 2024-10-28 04:33:34 UTC
README
Tired of those pesky fake email addresses in your submission forms?
EmailAddressVerifier
class lets you verify e-mail addresses for correct syntax and, optionally, for existence.
The following validation levels can be set with EmailAddressVerifier::validationLevel
property (defined by AddressValidationLevel
class):
- SyntaxCheck - validate email address by performing syntax check.
- DnsQuery - DNS MX lookup for domain part of the the e-mail address string, to find out the SMTP MX host responsible for e-mail delivery to the domain.
- SmtpConnection - test connection to the SMTP MX host.
- SendAttempt - test connection, sending
EHLO/HELO
andMAIL FROM
commands, and submitting the given e-mail address string inRCPT TO
command. This mimics normal send attempt, just without sending actual message data. If the server accepts the recipient and says "Yes, I'm ready to receive message data", the component just resets the connection and disconnects, reporting that the address is correct.
How to install (using composer):
Install using composer...
composer require "masroore/verifyemail"
In plain old PHP:
require 'vendor/autoload.php';
Usage basics: Check email address
To perform PHP email validation, import the VerifyEmail
namespace in your code:
use VerifyEmail\EmailAddressVerifier; use VerifyEmail\Utils;
To verify an e-mail address in your PHP project, use EmailAddressVerifier::verify()
method.
By default, EmailAddressVerifier.validationLevel is already SendAttempt (the most advanced e-mail address check available). Therefore we don't need to explicitly set this mode to perform all the checks possible against an e-mail address.
$verifier = new EmailAddressVerifier(); $verifier->setMailFrom('sender@domain.tld'); $verifier->setHelloDomain('domain.tld'); $verifier->setValidationLevel(AddressValidationLevel::SendAttempt); $result = $verifier->verify('check_email@domain.tld'); if ($result === AddressValidationLevel::OK) { echo 'Email verified'; }
The previous sample checked valid email address by instantiating the EmailAddressVerifier
object. For quick form validation in your PHP project you may use the EmailAddressVerifier::validate()
convenience method instead:
$level = null; if (EmailAddressVerifier::validate($email, $level)) { echo 'Email verified'; }
PHP email checker, email tester, email verifier, email validation, check email address, verify email address, free email verifier, test email address, valid email address