laravel maintained by stopreg
StopReg Laravel SDK
The official Laravel SDK for StopReg, providing seamless email and domain verification to protect your Laravel applications from fraudulent registrations.
Features
- Facade Support: Simple
StopReg::checkEmail()syntax. - Auto-Discovery: Automatic service provider and facade registration.
- Configurable: Easily publish and manage your API tokens.
- Validation-Ready: Perfect for use within Laravel request validation.
Installation
Install the package via composer:
composer require stopreg/laravel
Configuration
Publish the configuration file:
php artisan vendor:publish --tag="stopreg-config"
Then, add your StopReg API token to your .env file:
STOPREG_API_TOKEN=your_api_token_here
Usage
Using the Facade
You can use the StopReg facade to verify emails and domains anywhere in your application.
use StopReg;
// 1. Verify an email address
$result = StopReg::checkEmail('user@disposable.com');
if ($result['data']['classification']['is_disposable']) {
return back()->withErrors(['email' => 'Please use a permanent email address.']);
}
// 2. Verify a domain
$domainResult = StopReg::checkDomain('gmail.com');
echo $domainResult['data']['domain']['email_provider']; // "google"
In a Controller
public function register(Request $request)
{
$verification = StopReg::checkEmail($request->email);
if ($verification['data']['classification']['is_disposable']) {
// Block registration
}
}
Domain Verification
$result = StopReg::checkDomain('example.com');
$provider = $result['data']['domain']['email_provider'];
$mxFound = $result['data']['mail_server']['mx_found'];
Error Handling
The SDK throws an InvalidArgumentException for invalid inputs and StopRegException for API-level errors.
try {
StopReg::checkEmail('not-an-email');
} catch (\InvalidArgumentException $e) {
echo $e->getMessage();
}
License
MIT © StopReg