, (*1)
Email Validator plugin for Craft CMS 3
Email address validation for user registrations, custom forms and more., (*2)
, (*3)
, (*4)
, (*5)
Installation
Requirements
This plugin requires Craft CMS 3.0.0, or later., (*6)
Plugin Store
Log into your control panel and click on 'Plugin Store'. Search for 'Email Validator'., (*7)
Composer
- Open your terminal and go to your Craft project:
cd /path/to/project
- Then tell Composer to load the plugin:
composer require lukeyouell/craft-emailvalidator
- In the Control Panel, go to Settings → Plugins and click the “Install” button for Email Validator.
Configuration
You can toggle which checks are enforced by updating the plugin settings., (*8)
The following options are available:, (*9)
Name |
Default |
Description |
Typo Check & Suggestions |
enabled |
Provide an alternative email suggestion if a typo is detected in the domain part of the email address. |
MX Records |
disabled |
Allow domains that aren't configured to receive email. |
Catch All |
enabled |
Allow domains that are configured to catch all incoming mail traffic. |
Roles |
enabled |
Allow role-based email addresses. |
Free Providers |
enabled |
Allow email addresses found to be using a free email provider such as Gmail and Yahoo!. |
Disposable Providers |
disabled |
Allow email addresses found to be using a disposable email provider. |
Overriding Plugin Settings
If you create a config file in your config
folder called email-validator.php
, you can override the plugin's settings in the Control Panel. Since that config file is fully multi-environment aware, this is a handy way to have different settings across multiple environments., (*10)
Here's what that config file might look like along with a list of all of the possible values you can override., (*11)
<?php
return [
'typoCheck' => true,
'allowNoMX' => false,
'allowCatchAll' => true,
'allowRoles' => true,
'allowFree' => true,
'allowDisposable' => false,
// Contact Form plugin settings
'cfValidation' => true,
'cf_allowNoMX' => false,
'cf_allowCatchAll' => true,
'cf_allowRoles' => true,
'cf_allowFree' => true,
'cf_allowDisposable' => false,
];
Validating Email Addresses
User Management
The plugin will automatically enforce it's validation checks if Verify email addresses?
is checked in the user settings., (*12)
These settings can be found in Settings > Users > Settings
, (*13)
Templates
You can validate an email address from within your templates by using the following function:, (*14)
{% set validation = validateEmail('joe.bloggs@email.co.uk') %}
{{ validation|json_encode(constant('JSON_PRETTY_PRINT')) }}
This response will be returned., (*15)
If you have the Contact Form plugin installed you can validate submissions using Email Validator., (*16)
Email Validator will automatically detect if this plugin is installed, all you need to do is head to:, (*17)
Settings → Email Validator → Contact Form, (*18)
Plugins/Modules
You can also validate an email address from within your own plugins/modules:, (*19)
use lukeyouell\emailvalidator\EmailValidator;
EmailValidator::getInstance()->validationService->validateEmail('joe.bloggs@email.co.uk');
This response will be returned., (*20)
Response
Properties
email
The email address being validated., (*21)
user
The local part of the email address., (*22)
domain
The domain of the email address., (*23)
did_you_mean
Contains a 'did you mean' suggestion if a potential domain typo has been detected., (*24)
Returns true
or false
depending on whether or not the email address format is valid., (*25)
mx_found
Returns true
or false
depending on whether or not MX Records could be found for the requested domain., (*26)
catch_all
Returns true
or false
depending on whether or not the requested email address is found to be part of a catch-all mailbox., (*27)
role
Returns true
or false
depending on whether or not the requested email address is role-based. (e.g. 'admin@email.co.uk', 'support@email.co.uk'), (*28)
free
Returns true
or false
depending on whether or not the requested email address is found to be using a free email provider. (e.g. Gmail, Yahoo!), (*29)
disposable
Returns true
or false
depending on whether or not the requested email address is found to be using a disposable email provider., (*30)
Email Validator Roadmap
Some things to do, and ideas for potential features:, (*31)
- Switch to using jobs to update list of providers
- Console commands
- Custom rules validator
- SMTP verification
- Commerce integration
- Validation score
Brought to you by Luke Youell, (*32)