Article
Laravel Email Validation DNS Rule: What It Checks and What It Misses
By Unlimited Verifier Team ·

Summary
Laravel's email:rfc,dns rule checks that an address's domain has MX or fallback address records, so dead domains are rejected at signup. It does not confirm the mailbox exists, so typos on real domains and departed employees still get through.Laravel's built-in dns rule, written email:rfc,dns, checks that an address's domain has a mail-routing record (an MX record, or an A record as a fallback), so dead domains get rejected at signup. It does not prove the mailbox exists, and that gap is a common source of bounces after a signup form goes live.
For the broader case for checking addresses as people type them, see real-time email validation.
Quick answer
- What it checks: the domain after the
@has an MX record, or, if it has none, an A or AAAA record. The check makes one MX lookup, plus address-record lookups when no MX exists. - What it misses: whether the mailbox exists, whether the domain is catch-all, and whether the address is disposable or role-based.
- Known blind spots: a null MX record (RFC 7505) can pass a plain "has any MX record" check, and typo domains that are parked with mail records pass too.
- Practical setup: put
bailbefore the rule, cache results per domain, fail open when DNS errors out, and add a mailbox-level check for high-value signups and for cleaning existing lists.
What does Laravel's dns email rule actually check?
The dns rule looks up the domain's MX records and falls back to address records. It never contacts the mailbox. Laravel's email rules are built on the egulias/email-validator package, and the DNS step follows the implicit MX behaviour in RFC 5321, section 5.1, where a domain with no MX record is treated as its own mail exchanger if it has an address record. This reflects the package's public source as we read it, so confirm the exact behaviour against the version you have installed.
In practice:
jane.doe@acme-saas.compasses ifacme-saas.comhas mail records, even if Jane left the company years ago.jane@acme-saas.comalso passes if the domain is catch-all, because the server accepts any local part.jane@acme-sass.com(a typo) fails only if the typo domain has no mail or address records at all.
Bottom line: The dns rule answers "can this domain receive mail?" It does not answer "does this person have a mailbox?", and that second question drives most bounces.
How do you add the dns rule to a Laravel form request?
Put bail first, then email:rfc,dns, in a form request so validation stays out of your controllers. Check the Laravel validation documentation for the syntax your version supports.
- Confirm PHP can run DNS lookups. The check relies on PHP's resolver functions. Make sure
checkdnsrranddns_get_recordare not listed indisable_functionsinphp.ini, and that your server or container can reach a DNS resolver. - Add the rules in the right order.
bailstops validation at the first failure, so a malformed address never triggers a DNS lookup.
// app/Http/Requests/RegisterRequest.php
public function rules(): array
{
return [
'email' => [
'bail',
'required',
'max:254',
'email:rfc,dns',
'unique:users,email',
],
];
}
- Try the fluent builder if your version has it. Recent Laravel versions provide
Rule::email()with chainable methods such asrfcCompliant()andvalidateMxRecord(). Use it if you prefer chaining, and confirm the method names in your version's docs. - Test with an address that cannot receive mail. RFC 2606 reserves the
.invalidtop-level domain, sotest@example.invalidfails predictably. Use it in feature tests so they don't depend on live DNS. - Write a specific error message. The default text is generic. Say that the domain cannot receive email, so users know the problem is the domain and not their typing.
Bottom line: bail, email:rfc,dns and a .invalid test address cover the basics. The harder decisions come next, because the built-in rule has costs you won't see on day one.
Why is the built-in dns rule not enough for signup?
The built-in rule makes a live DNS call during every request, so it adds latency and depends on your resolver. It also misses cases that look valid. Four issues matter most in production.
It makes a network call on every request
A DNS lookup is fast on a healthy resolver, but a timeout can hold a PHP worker for several seconds. Signup traffic usually concentrates on a small set of domains, such as the major consumer providers and common corporate domains. Caching results per domain removes most of those repeated lookups.
A null MX record passes a simple check
RFC 7505 defines a "null MX": a record with preference 0 and target ., which tells senders that the domain accepts no mail. A check that asks only "is there an MX record?" sees one and says yes. You have to inspect the targets and reject a domain whose only MX target is the root.
Parked typo domains can pass
Some typo domains are parked by services that publish mail records for them. If a parked typo has MX records, the DNS check passes, even though nobody reads mail there. A DNS check catches typo domains that have no mail configuration. It cannot catch ones that are parked with one.
Resolver failures look like dead domains
If your resolver times out, a naive rule treats the lookup as a dead domain and rejects a real customer. This is the most damaging failure in practice, because it shows up as a sudden drop in signups. Treat resolver errors as "unknown" and let the address through.
Bottom line: The built-in rule is a good first filter. A cache, a null-MX check and a fail-open policy turn it into something you can run at scale.
Which domain check should you use in Laravel?
Use a layered approach. The built-in rule is the simplest option, a cached custom rule is the scalable one, and a mailbox-level API check answers the question neither of them can.
| Option | What it checks | Catches dead domains | Catches null MX | Catches missing mailbox | Cost model |
|---|---|---|---|---|---|
Built-in email:rfc,dns |
Syntax plus MX/A lookup | Yes | Not in the default check; verify your version | No | One uncached DNS lookup per validation |
Fluent Rule::email() with MX validation |
The same DNS check, written as a chain | Yes | Same as above | No | Same as above |
| Custom cached rule (shown below) | MX/A lookup, null-MX handling, cache per domain | Yes | Yes | No | One lookup per domain per cache window |
| Mailbox check via email verification API and automation | Syntax, domain/MX, SMTP mailbox, catch-all, disposable and role-based flags | Yes | Not a documented feature; test with a null-MX domain before relying on it | Partly, through the SMTP mailbox check, which can return Risky when SMTP is blocked | Per-API-call allowance; see the worked example |
For a language-neutral walkthrough of the MX lookup itself, see how to check MX records programmatically. For a Laravel implementation with caching and null-MX handling, use this custom rule:
// app/Rules/DeliverableDomain.php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Cache;
class DeliverableDomain implements ValidationRule
{
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$domain = strtolower((string) substr(strrchr((string) $value, '@'), 1));
if ($domain === '') {
return; // the email rule reports malformed addresses
}
$cacheKey = 'mail-domain:'.$domain;
$cached = Cache::get($cacheKey);
if ($cached === null) {
$result = $this->lookup($domain);
if ($result === null) {
return; // resolver error: unknown, so fail open and don't cache
}
// Positive results live 12 hours; negative results only 1 hour.
Cache::put($cacheKey, $result, now()->addMinutes($result ? 720 : 60));
$cached = $result;
}
if ($cached === false) {
$fail('The domain in :attribute cannot receive email.');
}
}
private function lookup(string $domain): ?bool
{
$mx = dns_get_record($domain, DNS_MX);
if ($mx === false) {
return null;
}
if ($mx !== []) {
$targets = array_map(fn ($r) => rtrim($r['target'] ?? '', '.'), $mx);
// A target of just the root means "accepts no mail" (RFC 7505).
return collect($targets)->contains(fn ($t) => $t !== '');
}
// No MX records: RFC 5321 implicit MX, so fall back to address records.
$a = dns_get_record($domain, DNS_A);
$aaaa = dns_get_record($domain, DNS_AAAA);
if ($a === false || $aaaa === false) {
return null;
}
return $a !== [] || $aaaa !== [];
}
}
Three cautions before you deploy it:
- Test NXDOMAIN handling first. The return value of
dns_get_recordcan befalseboth for a resolver failure and, depending on the environment, for a domain that does not exist. Check the PHPdns_get_recordreference and test with a nonexistent domain on your own servers. If a dead domain returnsfalse, the fail-open branch will let it through. - Negative results expire quickly on purpose. A domain can start accepting mail after a fix, so a one-hour cache for rejections limits how long a real customer stays blocked.
- The rule is a filter, not a verdict. It answers "can this domain receive mail?" and nothing more.
Bottom line: A cached, null-MX-aware rule costs nothing per check and removes most of the DNS overhead. It cannot confirm a mailbox, so it is never your only check.
What's the right validation stack for Laravel signups?
Run the cheapest checks first, and move the expensive mailbox check off the request path. Each layer removes a category of bad input before the next, costlier step runs.
- Check the format synchronously. Use
bail,email:rfcandmax:254. This costs no network time and catches typing errors at once. Pair it with client-side vs server-side email validation, so users fix mistakes before they submit. For the browser side, see how to validate email in JavaScript. - Check the domain synchronously, with the cached rule. This blocks dead and null-MX domains with at most one lookup per domain per cache window.
- Check uniqueness. Run
uniqueafter the domain check, so you don't query the database for addresses that were never going to work. - Queue the mailbox check. After the user is saved, dispatch a job that calls the email verification API and stores the result as Valid, Risky or Invalid. An SMTP check can take longer than a page request should, so keep it off the request path. Gate sensitive actions, such as billing or sending campaigns, on the stored status.
- Re-verify on a schedule. Lists decay, so re-run bulk checks monthly or quarterly. The email list maintenance best practices guide covers the cadence.
Why this order? Format errors cost nothing to catch. A domain check costs a cached lookup. A mailbox check costs an API call. Running each step only on what survived the previous one keeps the expensive calls for addresses that could actually work.
If you are building the form from scratch, how to add real-time email verification to signup forms covers the UX side, including how to show "Risky" results without blocking legitimate users.
Bottom line: Run the cheap checks inline and the mailbox check in a queue. Users get instant feedback, and your database only stores addresses that have passed the checks that matter.
Worked example: 8,000 monthly signups and a 60,000-row backlog
The figures below are illustrative assumptions, chosen to show the arithmetic. The plan limits are real. This is a common pattern for SaaS teams, which is the core use case for email verification for ecommerce and SaaS.
Scenario: A SaaS company takes about 8,000 signups a month through a Laravel form. It also has 60,000 legacy users who were never verified.
Step 1: Domain rule at signup. Assume 1.5% of submissions fail the cached domain check. That is 0.015 × 8,000 = 120 signups a month rejected before a row is created.
Step 2: Mailbox check for the rest. The remaining 7,880 signups each take one API call. The Pro plan includes 100,000 API emails a month, so that uses 7,880 of 100,000 and leaves 92,120.
Step 3: Backlog by upload, not API. Pro lists hold up to 25,000 emails each, so split the backlog:
| File | Rows | Note |
|---|---|---|
| 1 | 25,000 | Pro list maximum |
| 2 | 25,000 | Pro list maximum |
| 3 | 10,000 | Remainder (60,000 − 50,000) |
Upload the three files through Upload and verify a list. Standard verification is unlimited on every plan, so checking all 60,000 rows adds no per-email fee. Deep verification draws from the 25,000-per-month allowance, so spend it on the oldest, least-engaged segment, for example the 25,000 records with no opens in over a year.
Step 4: Why verify before sending? Assume 6% of the backlog is invalid. That is 0.06 × 60,000 = 3,600 addresses that would bounce if you mailed the whole list unverified. Removing them first is the difference between a clean sending record and a suspension review.
Step 5: Cost. The Pro plan costs $29 a month, or $25 a month billed annually. If you use the full 100,000-email API allowance, $29 works out to $0.29 per 1,000 emails, or $0.25 per 1,000 on the annual plan. That is arithmetic on the plan allowance, not a per-email fee. For a wider view of how plans compare, see email verification pricing.
Result: For about $29 in the month, the company stops rejecting valid customers at the form, checks each new signup's mailbox, and removes an estimated 3,600 invalid addresses from the backlog before the next campaign.
Bottom line: The backlog fits in three uploads, the signup checks fit inside the API allowance, and the arithmetic shows which limit binds first.
How do you clean an existing Laravel user table?
Cleaning an existing table is an export, verify and write-back job. Unlimited Verifier has no native Laravel or ESP integrations, so you move data through a CSV, or through the API from your own scripts. These steps assume you run them with Artisan or Tinker on the application server.
- Export the addresses with their IDs. A chunked query keeps memory flat on a 60,000-row table. The
idcolumn is what lets you write results back later.
$handle = fopen(storage_path('app/emails.csv'), 'w');
fputcsv($handle, ['id', 'email']);
User::query()
->whereNotNull('email')
->chunkById(5000, function ($users) use ($handle) {
foreach ($users as $user) {
fputcsv($handle, [$user->id, $user->email]);
}
});
fclose($handle);
- Test a sample first. Create a free account and upload a sample of up to 150 addresses. The Free plan allows 25 lists a month of up to 150 emails each, but it has no API access. Use the sample to confirm the output format before the full run.
- Split the file to fit the list limit. On Pro, each list holds up to 25,000 emails. Split the export into files of that size or smaller.
- Upload and verify. Upload each file. Files up to 10MB are accepted, and the email column is detected automatically.
- Read the three buckets. Valid addresses are safe to keep. Invalid addresses should be suppressed. Risky addresses need a decision. Catch-all domains accept every address, so a Risky result there means the mailbox cannot be confirmed. The Catch-all email verification page explains how those results are handled. Disposable and role-based addresses are flagged too, so you can decide per segment whether to keep them. To spot-check one address, use the free email checker.
- Export and keep the results. Download them as CSV, Excel or JSON. Free-plan results are kept for 24 hours and Pro-plan results for 30 days, so export promptly and store your own copy.
- Write the statuses back by ID. Load the Invalid list into a suppression table, and set a status column on
usersin a chunked update, matching on theidfrom your export. Don't delete invalid users outright. The suppression record is what stops them returning in the next import.
Verification shows that a mailbox exists. It does not show that the person opted in. Check consent records separately before you mail anyone, as covered in email verification compliance and hygiene.
Bottom line: Export with IDs, verify in chunks within the list cap, and write statuses back by ID rather than deleting rows.
What are the common mistakes with Laravel DNS validation?
- Treating the dns rule as proof of a mailbox. It proves the domain has mail or address records, nothing more. Add a mailbox check for anything that affects billing or sending.
- Checking only MX records. A domain with only an A record can still receive mail under RFC 5321's implicit MX rule. Rejecting it on an MX-only check loses real customers.
- Running uncached lookups on every request. Signups cluster on a few domains, so caching by domain is the cheapest performance fix.
- Failing closed on resolver errors. When DNS times out, the safer default is "unknown, let it through", not "invalid".
- Trusting
falsewithout testing it. If your environment returnsfalsefor nonexistent domains, dead domains will pass the fail-open branch. Test before you deploy. - Testing against live DNS. Feature tests that hit real domains are slow and flaky. Use
.invalidaddresses and keep the network out of the test suite. - Blocking signups on SMTP results. Many hosting providers and cloud networks block outbound SMTP, so mailbox checks can fail for reasons unrelated to the address. Why SMTP email verification gets blocked covers the common causes. Queue these checks and show "unconfirmed" rather than rejecting.
- Expecting API access on the Free plan. Free has no API access. Build signup checks on Pro, and use Free only for sampling and small uploads.
- Ignoring API rate limits during backfills. A backlog script that fires requests in bursts can hit limits. Plan batch sizes with email validation API rate limits explained in mind.
- Deleting invalid users. Suppress them instead, so a later re-import can't bring them back.
- Assuming a stored result never ages. Domains lapse, mailboxes close, and catch-all settings change. Re-check on a schedule.
Bottom line: Most Laravel DNS validation failures come from three habits: treating a domain check as a mailbox check, failing closed when the network misbehaves, and skipping the cache.
If you validate in another stack, the layering stays the same. For Java, see email validation in Java Spring Boot. For a side-by-side look at the mailbox layer, see the best email verification tools comparison.
How we compared (and limitations)
This article is based on public documentation and package behaviour: the Laravel validation documentation, the PHP dns_get_record and checkdnsrr references, the egulias/email-validator package, and RFCs 5321, 7505 and 2606. We have not benchmarked these approaches against each other or measured resolver latency, and we have not run the code against a live environment.
Limits to keep in mind:
- Laravel versions differ. The fluent
Rule::email()builder and its method names depend on your framework version, so check the docs for yours. - Null-MX and NXDOMAIN behaviour varies by environment. Confirm both with a test domain on your own servers before you rely on the fail-open branch.
- Worked-example figures are illustrative. The 8,000 signups, 1.5% domain failure rate, 60,000-row backlog and 6% invalid rate are assumptions chosen to show the arithmetic.
- Vendor figures are the vendor's. Unlimited Verifier states 99.5% accuracy for deep verification. That is the company's own figure, not an independent benchmark.
Plan details are taken from Unlimited Verifier's published plan facts: unlimited standard verification on every plan, up to 25,000 emails per list and 25,000 deep verifications a month on Pro, 100,000 API emails a month on Pro, and no API access on Free.
What the dns rule passes and fails
| Address | Result | Why |
|---|---|---|
| jane.doe@acme-saas.com | Passes | Domain has MX; mailbox may not exist |
| jane@acme-saas.com (catch-all) | Passes | Server accepts any local part |
| jane@acme-sass.com | Fails | Typo domain has no mail or address records |
| user@nonexistent-domain-xyz.test | Fails | No MX or A/AAAA record |
Frequently asked questions
Does Laravel's dns rule check if an email mailbox exists?
No. The email:rfc,dns rule only checks that the domain has MX or fallback address records. It never connects to the mail server to confirm that a specific mailbox exists, so a valid-looking address on a real domain can still bounce.
What is the difference between email:rfc and email:dns in Laravel?
The rfc option checks that the address follows RFC syntax rules, while the dns option checks that the domain can receive mail. Combining them as email:rfc,dns runs both checks, with the DNS lookup only performed when the syntax passes.
Why should I put bail before the email rule?
Adding bail stops validation at the first failing rule. A malformed address then never triggers a DNS lookup, which saves time and avoids unnecessary network calls on obviously invalid input.
Can the dns rule slow down my signup form?
Yes, because each check performs a live DNS lookup that adds network latency. Caching results per domain reduces repeated lookups for common providers, and keeping bail first prevents lookups on malformed input.
What should happen if DNS lookups fail on my server?
Most teams choose to fail open, accepting the address and logging the DNS error, so a resolver outage does not block legitimate signups. The trade-off is that some dead domains may get through until DNS recovers.
Does a null MX record pass Laravel's dns check?
It can. RFC 7505 defines a null MX record to signal that a domain accepts no mail, and a plain check for any MX record may treat it as valid. Test this case if your rejection logic depends on it.
Does the dns rule catch disposable email addresses?
No. Disposable and role-based addresses use real, working domains, so the dns rule passes them. You need a separate disposable-domain list or a dedicated validation service to block them.
How do I check mailboxes instead of just domains?
Use a mailbox-level verification service, typically through an SMTP check or a third-party API, for high-value signups or list cleaning. These checks add cost and latency, so run them selectively rather than on every keystroke.
Cut Bounces and Protect Your Sender Reputation With Unlimited Email Verification
Every invalid address you send to hurts your sender reputation and your inbox placement. Verifying your list before each send means fewer bounces, healthier deliverability, and a predictable cost. With Unlimited Verifier, standard verification is unlimited on every plan, with no per-email fees.
Unlimited Verifier checks syntax, domain, MX records and the SMTP mailbox. It also detects catch-all domains and flags disposable and role-based addresses. Export a CSV from your email platform or CRM, upload and verify the list, then re-import the clean results. You can also automate checks with the email verification API.
| Free | Pro | |
|---|---|---|
| Price | $0 | $29/month ($25/month billed annually) |
| Lists | 25 a month, up to 150 emails each | Unlimited, up to 25,000 emails each |
| Deep verifications | 750 a month | 25,000 a month |
| API access | No | Yes (100,000 emails a month) |
| Result retention | 24 hours | 30 days |
Why teams choose Unlimited Verifier
- Unlimited standard verification on all plans, including Free, with no per-email fees.
- Catch-all detection so you know which domains accept every address.
- Clear Valid / Risky / Invalid results, exportable as CSV, Excel or JSON.
- An open-source verification engine you can inspect on GitHub.
Unlimited Verifier states 99.5% accuracy for deep verification.
Create a free account and verify your next list before you hit send.
Want to test a single address first? Try the free email checker.