mailboxvalidator/mailboxvalidator-yii

MailboxValidator Yii framework extension to validate an email by using MailboxValidator API.

2.1.0 2023-12-05 08:06 UTC

This package is auto-updated.

Last update: 2024-12-05 10:25:29 UTC


README

MailboxValidator Yii Email Validation Extension enables user to easily validate if an email address is valid, a type of disposable email or free email.

This extension can be useful in many types of projects, for example

  • to validate an user's email during sign up
  • to clean your mailing list prior to email sending
  • to perform fraud check
  • and so on

Installation

Install this extension by using Composer:

composer require mailboxvalidator/mailboxvalidator-yii

Dependencies

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 EmailValidation('PASTE_YOUR_API_KEY_HERE');

or like this:

['email', MailboxValidator::className(), 'option'=>'YOUR_SELECTED_OPTION','api_key'=>'PASTE_YOUR_API_KEY_HERE',],

Functions

EmailValidation (api_key)

Creates a new instance of the MailboxValidator object with the API key.

validateDisposable (email_address)

Check whether the email address is belongs to a disposable email provider or not. Return Values: True, False

validateFree (email_address)

Check whether the email address is belongs to a free email provider or not. Return Values: True, False

validateEmail (email_address)

Performs email validation on the supplied email address.

Return Fields

isDisposableEmail (email_address)

Check if the supplied email address is from a disposable email provider.

Return Fields

isFreeEmail (email_address)

Check if the supplied email address is from a free email provider.

Return Fields

Usage

Form Validation

To use this library in form validation, first call this library in your model like this:

use MailboxValidator\MailboxValidator;

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.

Email Validation

To use this library to get validation result for an email address, firstly load the library in your controller like this:

use MailboxValidator\EmailValidation;

After that, you can get the validation result for the email address like this:

$mbv = new EmailValidation(Yii::$app->params['mbvAPIKey']);
$results = $mbv->isFreeEmail('example@example.com');

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 above.

Errors

Copyright

Copyright (C) 2018-2023 by MailboxValidator.com, support@mailboxvalidator.com