MailboxValidator Yii framework extension to validate an email by using MailboxValidator API.
MailboxValidator Yii Email Validation Extension provides an easy way to call the MailboxValidator API which validates if an email address is valid.
Install this extension by using Composer:
composer require mailboxvalidator/mailboxvalidator-yii
An API key is required for this module to function.
Go to https://www.mailboxvalidator.com/plans#api to sign up for FREE API plan and you'll be given an API key.
After you get your API key, open your
config/params.php and add the following line into the array:
'mbvAPIKey' => 'PASTE_YOUR_API_KEY_HERE',
You can also set you API key in controller after calling library. Just do like this:
$mbv = new SingleValidation('PASTE_YOUR_API_KEY_HERE');
or like this:
['email', MailboxValidator::className(), 'option'=>'YOUR_SELECTED_OPTION','api_key'=>'PASTE_YOUR_API_KEY_HERE',],
Below are the methods supported in this library.
|validateEmail||Return the validation result of an email address. Please visit MailboxValidator for the list of the response parameters.|
|validateFree||Check whether the email address is belongs to a free email provider or not. Return Values: True, False|
|validateDisposable||Check whether the email address is belongs to a disposable email provider or not. Return Values: True, False|
To use this library in form validation, first call this library in your model like this:
After that, in the function rules, add the new validator rule for the email:
['YOUR_EMAIL_FIELD_NAME', MailboxValidator::className(), 'option'=>'disposable,free',],
In this line, the extension is been called, and you will need to specify which validator to use. The available validators are disposable and free. After that, refresh you form and see the outcome.
To use this library to get validation result for an email address, firstly load the library in your controller like this:
After that, you can get the validation result for the email address like this:
$mbv = new SingleValidation(Yii::$app->params['mbvAPIKey']); $results = $mbv->FreeEmail('firstname.lastname@example.org');
To pass the result to the view, just simply add the $results to your view loader like this:
return $this->render('YOUR_VIEW_NAME', ['results' => $results]);
And then in your view file, call the validation results. For example:
echo 'email_address = ' . $results->email_address . "<br>";
You can refer the full list of response parameters available at here.
|101||API key not found.|
|102||API key disabled.|
|103||API key expired.|
Copyright (C) 2018 by MailboxValidator.com, email@example.com