Integrations · Frameworks and SDKs

Validate emails in apps on Laravel Forge

Laravel Forge deploys your app; the check runs in your app's code. For a Laravel app that is our Laravel validation rule, which rejects an address that cannot receive email in any form request. Forge's part is the key: it goes in the site's environment, from Forge's Environment panel, never in your repository. Forge adds nothing of its own and needs no plugin.

By default the rule never stops a real person when the API cannot answer in time: the address passes and a warning goes to your log (EV_FAIL_OPEN, below).

Add the rule to your app

Install the package in your app as the Laravel guide says: it is not on Packagist yet, so commit the downloaded zip in a folder of your repository (for example packages/) with the Composer repository line, and commit composer.json and composer.lock. Forge's deployment then installs it with the rest of your dependencies. Add the rule to your form requests:

'email' => ['bail', 'required', 'email', new ValidEmail()],

The key in Forge

  1. Create an API key on the API keys page with the permission "Validate addresses", one for each site, with a daily credit cap. Put the form's route behind Laravel's throttle middleware: each address a visitor sends can use a credit.

  2. In Forge, open the site, then Settings → Environment, and add:

    EV_API_KEY=your-api-key

    Forge writes it to the site's .env file (shared by every release with zero-downtime deployments).

  3. Save with Forge's option to run php artisan config:cache (on Laravel and Statamic sites), so a cached configuration reads the new value; tick php artisan queue:restart too if you validate in queued jobs.

Optional settings go in the same panel: EV_BLOCK_DISPOSABLE=true to reject throwaway inboxes too, EV_FAIL_OPEN=false to fail the field when the check cannot finish, and EV_BASE_URL=https://api-eu.email-validation.org for EU data residency (the same key works on both). The settings list every one.

Try it

Send the form with no_mailbox@sandbox.email-validation.org: the field fails. accepted@sandbox.email-validation.org passes. These test addresses cost nothing and contact no mail server.

Not a Laravel app

Forge also deploys other PHP apps and Node.js apps. The Environment panel writes the same .env file, which your app loads itself (in Node.js, for example, with node --env-file=.env). Read EV_API_KEY from the environment with one of our SDKs, such as the PHP or the JavaScript one, and let the form through when the check fails, so an outage on our side never stops a visitor. There are official SDKs for JavaScript/TypeScript, Python, Go, PHP, Ruby, C#, Rust and Swift; those for Java, Kotlin, Dart, Elixir, C and Perl are built and tested and coming soon to their package registries.

Forge's own documentation: Environment variables.

More on Laravel Forge

Updated · Maintained by: Email Validation LLC

Need help? Contact support, or ask the help chat. Something wrong or missing on this page? Tell us