Giter Site home page Giter Site logo

hendurhance / laravel-spam-email Goto Github PK

View Code? Open in Web Editor NEW
39.0 2.0 7.0 1.04 MB

๐Ÿฅณ๐Ÿ” Protect your users from using spam emails on signup/form/apis in your Laravel apps

License: MIT License

PHP 100.00%
composer laravel package packagist php validation email email-validation email-validator php-sd sdk validator email-validator-api library php-library spam-detection spam-filtering

laravel-spam-email's Introduction

Laravel SpamMailChecker

Latest Version on Packagist Total Downloads Latest Unstable Version License PHP Version Require Made in Nigeria

A powerful Laravel package designed to effortlessly validate email addresses against various spam mail providers using a diverse range of drivers. Seamlessly integrated with Laravel's validation system, this package offers comprehensive support for validating email inputs in forms and RESTful APIs

Supported Email Validation Services

Service Descriptions Driver Documentation Supported
Local A local text list of spam email domains. local Read More โœ… Yes
Remote Using PHP In-built functions getmxrr(), checkdnsrr(). fsockopen() to validate email domain remote Read More โœ… Yes
AbstractApi Using Abstract's suite of API to validate email domains abstractapi Read More โœ… Yes
QuickEmailVerification A reliable, accurate, affordable, and advanced email verification service quickemailverification Read More โœ… Yes
Verifalia A web-based email validation service which allows to upload and validate lists of email addresses with ease verifalia Read More โœ… Yes
SendGrid A cloud-based SMTP provider that allows you to validate email addresses before you send. sendgrid Read More โœ… Yes

NOTE: More services will be added soon. (You can also contribute to this project by adding more services - ZeroBounce, Mailboxlayer, EmailListVerify, Emailable, etc)

Installation

You can install the package via composer:

composer require martian/spammailchecker
Martian\SpamMailChecker\SpamMailCheckerServiceProvider::class,
  • If you are going to be using the facade, you'll need to register it as well. Open config/app.php and add the following line to the aliases array:
'SpamMailChecker' => Martian\SpamMailChecker\Facades\SpamMailChecker::class,

Publish Configuration File

Publish the configuration file using the following command:

php artisan vendor:publish --provider="Martian\SpamMailChecker\Providers\SpamMailCheckerServiceProvider"

Configuration

The configuration file is located at config/laravel-spammail-checker.php. You may configure the package to use any of the supported drivers. The default driver is local which uses a local text list of spam email domains.

Local Driver Configuration

  • In order to use localas your driver of choice, you need to set the default key in the config/laravel-spammail-checker.php configuration file to local:

        'default' => 'local',
  • Or you can set the SPAM_MAIL_CHECKER_DEFAULT_DRIVER environment variable to local in your .env file.

        SPAM_MAIL_CHECKER_DEFAULT_DRIVER=local
  • The local driver uses a local text list of spam email domains. The file is located at resources/config/emails.txt. You can include more domains by adding them to the blacklist array or exclude domains by adding them to the whitelist array.

        'drivers' => [
            'local' => [
                ...
                'whitelist' => [
                    // Add domains you want the local driver to ignore here
                    'gmail.com',
                    'yahoo.com',
                ],
                'blacklist' => [
                    // Add domains you want the local driver to validate against here
                    'mailinator.com',
                    'spam.com',
                ],
            ]
        ]
  • Clear the config and cache using the following commands after making changes to the configuration file:

        php artisan optimize:clear

NOTE: The local driver is case-insensitive. So, you don't need to worry about the case of the email domain.

Remote Driver Configuration

  • In order to use remote as your driver of choice, you need to set the default key in the config/laravel-spammail-checker.php configuration file to remote:

        'driver' => 'remote',
  • Or you can set the SPAM_MAIL_CHECKER_DEFAULT_DRIVER environment variable to remote in your .env file.

        SPAM_MAIL_CHECKER_DEFAULT_DRIVER=remote
  • The remote driver uses PHP In-built functions getmxrr(), checkdnsrr(). fsockopen() to validate email domain. You can configure the remote driver on whether to check for MX - getmxrr(), DNS - checkdnsrr(), and SMTP -fsockopen or validate email domain. You can also configure the timeout value in seconds.

        'drivers' => [
            ...
            'remote' => [
                ...
                'check_dns' => true, // When set to true, it will check for DNS
                'check_smtp' => false, // When set to true, it will check for SMTP
                'check_mx' => false, // When set to true, it will check for MX record
                'timeout' => 60 * 5, // 5 minutes
            ]
        ]

AbstractApi Driver Configuration

  • In order to use abstractapi as your driver of choice, you need to set the default key in the config/laravel-spammail-checker.php configuration file to abstractapi:

        'default' => 'abstractapi',
  • Or you can set the SPAM_MAIL_CHECKER_DEFAULT_DRIVER environment variable to abstractapi in your .env file.

        SPAM_MAIL_CHECKER_DEFAULT_DRIVER=abstractapi
  • Add your ABSTRACTAPI_API_KEY AbstractAPI key you got from here to your env file.

    ABSTRACTAPI_API_KEY=abstractapi_api_key
    
  • You can configure the score to determine the threshold for a valid email address. The score ranges from 0 to 1. The higher the score, the more likely the email address is valid. You can also accept disposable email addresses by setting accept_disposable to true.

        'drivers' => [
            ...
            'abstractapi' => [
                ...
                'score' => 0.5, // 0.5 is the default score
                'accept_disposable_email' => true // When set to true, it will accept disposable email addresses
            ]
        ]

QuickEmailVerification Driver Configuration

  • In order to use quickemailverification as your driver of choice, you need to set the default key in the config/laravel-spammail-checker.php configuration file to quickemailverification:

        'default' => 'quickemailverification',
  • Or you can set the SPAM_MAIL_CHECKER_DEFAULT_DRIVER environment variable to quickemailverification in your .env file.

        SPAM_MAIL_CHECKER_DEFAULT_DRIVER=quickemailverification
  • Add your QUICKEMAILVERIFICATION_API_KEY QuickEmailVerification key you got from here to your env file.

    QUICKEMAILVERIFICATION_API_KEY=quickemailverification_api_key
  • You can configure the driver to accept disposable email addresses by setting accept_disposable to true.

        'drivers' => [
            ...
            'quickemailverification' => [
                ...
                'accept_disposable' => true, // When set to true, it will accept disposable email addresses
            ]
        ]

Verifalia Driver Configuration

  • In order to use verifalia as your driver of choice, you need to set the default key in the config/laravel-spammail-checker.php configuration file to verifalia:

        'default' => 'verifalia',
  • Or you can set the SPAM_MAIL_CHECKER_DEFAULT_DRIVER environment variable to verifalia in your .env file.

        SPAM_MAIL_CHECKER_DEFAULT_DRIVER=verifalia
  • In order to use verifalia service, you need to set login credentials in your env file. You can get your credentials from after you create a user here.

    VERIFALIA_USERNAME=verifalia_username
    VERIFALIA_PASSWORD=verifalia_password
  • You can configure the driver to accept disposable email addresses by setting accept_disposable to true.

        'drivers' => [
            ...
            'verifalia' => [
                ...
                'accept_disposable' => true, // When set to true, it will accept disposable email addresses
            ]
        ]

NOTE: A user on verifalia needs to be granted permission to use the API. You can do this by going here and clicking on the edit user you want to grant permission to. Then click on the Permissions tab and check the appropriate permissions on Email validations section.

SendGrid Driver Configuration

  • In order to use sendgrid as your driver of choice, you need to set the default key in the config/laravel-spammail-checker.php configuration file to sendgrid:

        'default' => 'sendgrid',
  • Or you can set the SPAM_MAIL_CHECKER_DEFAULT_DRIVER environment variable to sendgrid in your .env file.

        SPAM_MAIL_CHECKER_DEFAULT_DRIVER=sendgrid
  • Add your SENDGRID_API_KEY Sendgrid key you got from here to your env file.

      SENDGRID_API_KEY=sendgrid_api_key
  • You can configure the driver to accept disposable email addresses by setting accept_disposable to true. Score can also be configured to determine the threshold for a valid email address. The score ranges from 0 to 1. The higher the score, the more likely the email address is valid. Source can also be configured to determine the source of the email address. The source can be signup or contact.

        'drivers' => [
            ...
            'sendgrid' => [
                ...
                'score' => 0.5, // 0.5 is the default score
                'accept_disposable' => true, // When set to true, it will accept disposable email addresses
                'source' => 'signup' // The source is signup by default
            ]
        ]

Usage

In order to use the package, you need to call the spammail validation rule in your validation rules. You can also change the rule name to whatever you want in the config/laravel-spammail-checker.php configuration file under the rule key, likewise the error message under the error_message key.

/**
 * Get a validator for an incoming registration request.
 *
 * @param  array  $data
 * @return \Illuminate\Contracts\Validation\Validator
 */
protected function validator(array $data)
{
    return Validator::make($data, [
        'email' => 'required|spammail|max:255',
    ]);
}

Or make use of spammail in your Requests file like this:

 /**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return [
        'email' => 'required|spammail|max:255',
    ];
}

Adding Custom Error Message

A custom error message can be added to the spammail validation rule.

    'email.spammail' => 'This email address is invalid.', // Custom error message

Or you can change the error message in the config/laravel-spammail-checker.php configuration file under the error_message key.

    'error_message' => 'This email address is invalid.', // Custom error message

Using Classes Directly

You can also use the classes directly without using the spammail validation rule. This is useful when you want to use the package in your own custom validation rule or your own custom class.

use Martian\SpamMailChecker\SpamMailChecker;

public function checkEmail($email)
{
    $spamMailChecker = new SpamMailChecker();
    $spamMailChecker->validate($email);
}

Using Facade

You can also use the SpamMailChecker class directly without instantiating it.

use Martian\SpamMailChecker\Facades\SpamMailChecker;

public function checkEmail($email)
{
    SpamMailChecker::validate($email);
}

Using Each Driver Individually

You can also use each driver individually without using the spammail validation rule. This is useful when a certain driver is needed in a particular situation.

Using VerifaliaDriver
use Martian\SpamMailChecker\Drivers\VerifaliaDriver;

public function checkEmail($email)
{
    $verifaliaDriver = new VerifaliaDriver();
    $verifaliaDriver->validate($email);
}
Using SendGridDriver
use Martian\SpamMailChecker\Drivers\SendGridDriver;

public function checkEmail($email)
{
    $sendGridDriver = new SendGridDriver();
    $sendGridDriver->validate($email);
}
Using AbstractApiDriver
use Martian\SpamMailChecker\Drivers\AbstractApiDriver;

public function checkEmail($email)
{
    $abstractApiDriver = new AbstractApiDriver();
    $abstractApiDriver->validate($email);
}
Using RemoteDriver
use Martian\SpamMailChecker\Drivers\RemoteDriver;

public function checkEmail($email)
{
    $remoteDriver = new RemoteDriver();
    $remoteDriver->validate($email);
}
Using LocalDriver
use Martian\SpamMailChecker\Drivers\LocalDriver;

public function checkEmail($email)
{
    $localDriver = new LocalDriver();
    $localDriver->validate($email);
}
Using QuickEmailVerificationDriver
use Martian\SpamMailChecker\Drivers\QuickEmailVerificationDriver;

public function checkEmail($email)
{
    $quickEmailVerificationDriver = new QuickEmailVerificationDriver();
    $quickEmailVerificationDriver->validate($email);
}

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please feel free to fork this project and make a pull request. For more information check CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-spam-email's People

Contributors

dsbilling avatar hendurhance avatar yoeriboven avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-spam-email's Issues

โš ๏ธ Valid Emails Returning Error

After major testing, some valid domains by Google Spam Detection mark some domains as valid

This .txt file has to go through a major overhaul in order to fix this. (Can be a major issue for users' signups on apps in which "laravel-spam-mail" package was implemented)

image

For Context: The image above live.com and icloud.com domain are listed as spam which are not.

Issue with installation of your package

I got an error throw when installing your package. Below is the error:

/d/Projects/google-tracking-app/$ composer require martian/spammailchecker
Using version ^1.2 for martian/spammailchecker
./composer.json has been updated
Running composer update martian/spammailchecker
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires martian/spammailchecker ^1.2 -> satisfiable by martian/spammailchecker[1.2].
    - martian/spammailchecker 1.2 requires illuminate/support ~7|~8.0 -> found illuminate/support[v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it confl
icts with another require.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require martian/spammailchecker:*" to figure out if any version is installable, or "composer re
quire martian/spammailchecker:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

How can it be fixed please? Thanks.

Deprecation Log

Hello, We are using version 2.0 in our project. It shows 2.0 in composer.json as well. but we keep getting the following log. Tried uninstalling, cache remove, vendor, remove, and event composer.lock remove. still, we are getting this log.

Since martian/spammailchecker 1.0.0: This package is deprecated and will no longer be maintained. Please use version 2.0.0 or higher. in /home/{full_path}/vendor/symfony/deprecation-contracts/function.php on line 25

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.