Laravel · PHP

Block disposable email in Laravel

Create a custom validation rule and attach it to your RegisterRequest or Fortify/Breeze signup form.

The code

<?php
// app/Rules/NotDisposableEmail.php
namespace App\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Http;

class NotDisposableEmail implements ValidationRule
{
    public function validate(string $attribute, mixed $value, Closure $fail): void
    {
        try {
            $response = Http::timeout(5)
                ->withToken(config('services.piisend.key'))
                ->get('https://api.piisend.com/api/v1/check/email/' . urlencode($value));

            // reject on 'block' — catches disposable, spam, no-MX and typo'd addresses
            if ($response->successful() && $response->json('recommendation') === 'block') {
                $fail('Please use a permanent email address.');
            }
        } catch (\Throwable $e) {
            // fail open
        }
    }
}

// app/Http/Requests/RegisterRequest.php
public function rules(): array
{
    return [
        'email' => ['required', 'email', new \App\Rules\NotDisposableEmail],
        'password' => ['required', 'confirmed', Rules\Password::defaults()],
    ];
}

API key

Add `piisend.key` to `config/services.php` from `PIISEND_API_KEY` env.

Fail-open vs fail-closed

Empty catch allows signup on outage — log exceptions in production.

Pair with verification

Works with Laravel Fortify, Breeze, or Jetstream register controllers.

FAQ

Where does the Piisend API key go in Laravel?

Add `piisend.key` to `config/services.php` from `PIISEND_API_KEY` env.

What happens if Piisend is slow or down?

Empty catch allows signup on outage — log exceptions in production.

How does this fit with the rest of Laravel signup?

Works with Laravel Fortify, Breeze, or Jetstream register controllers.

What does this snippet block?

Addresses on disposable domains: about 10,900 listed domains, plus new ones whose mail servers belong to a known throwaway service. Free providers such as Gmail and forwarding aliases such as duck.com pass.

Can I get a full allow / review / block verdict instead?

Yes, and we recommend it. Call GET /api/v1/check/email/{email} instead. Both endpoints need an API key with the check:read scope and use one check from your monthly allowance per call, but the check endpoint also returns forwarding relays, phishing lists, missing MX records, new domains, typo suggestions and an allow / review / block verdict.

Send verification email with Piisend

After blocking disposable addresses, send OTP and verification mail through the same Piisend account. One API key for intelligence checks and transactional sends.