Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Email Validator Laravel Package

egulias/email-validator

RFC-focused email validation library for PHP. Validates addresses against RFC 5321/5322/6530-6532 and 1035 with pluggable strategies (RFC, DNS, spoof checks). Designed for strict parsing and modern PHP (8.1+) projects via Composer.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package with Composer:

composer require egulias/email-validator  

Then, use the basic EmailValidator class with a validation strategy. The simplest approach is RFC-compliant validation:

use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\RFCValidation;

$validator = new EmailValidator();
isValid('[email protected]', new RFCValidation()); // true

This covers standard email structure per RFC 5321/5322. For production-grade validation, combine validations (e.g., RFCValidation + DNSCheckValidation) via MultipleValidationWithAnd.

Implementation Patterns

  • Combine validations for layered checks: Use MultipleValidationWithAnd to enforce both structural validity (RFC) and domainReachability (DNS).
    $validator->isValid('[email protected]', new MultipleValidationWithAnd([
        new RFCValidation(),
        new DNSCheckValidation() // Requires PHP Intl
    ]));
    
  • Laravel integration: Use custom rules or macroable form request validation:
    Rule::required()-> Rule::email()->validateUsing(fn($attribute, $value) => (new EmailValidator())->isValid($value, new RFCValidation()))
    
    Or build a reusable Validator class.
  • Extensibility: Implement EmailValidation interface for custom rules (e.g., blocklist, disposable-domain filtering, or custom business logic). Example:
    class BlocklistValidation implements EmailValidation {
        public function isValid($email, $extraData = null): bool {
            return !in_array($this->extractDomain($email), $this->blocklist);
        }
    }
    
  • Debug warnings: NoRFCWarningsValidation fails on RFC deviations (e.g., comments, obsolete syntax), useful for strict compliance requirements.
  • For internationalized domains: Ensure PHP Intl is installed; otherwise DNSCheckValidation and SpoofCheckValidation won’t work.

Gotchas and Tips

  • PHP version matters: v4.x requires PHP 8.1+; older versions (v3.x) are EOL. Always match version to your app’s PHP constraint.
  • DNS checks are brittle: DNS lookups can fail silently or timeout. Wrap usage in try/catch or use asynchronous validation (e.g., queue-based confirmation) for latency-sensitive apps.
  • Spoofing is subtle: SpoofCheckValidation catches visually similar unicode (e.g., Cyrillic а vs Latin a), but it’s only reliable with Intl enabled.
  • TLD-only domains: RFC-compliant but rare (e.g., user@localhost). Library flags them as warnings (not errors) unless NoRFCWarningsValidation is used.
  • Testing: Use EmailValidator::getWarnings() after validation to debug subtle issues (e.g., deprecated comments, domain formatting quirks).
  • Performance: DNSCheckValidation is expensive. Consider caching results or deferring to post-signup email verification (e.g., confirmation link).
  • Extensibility: The EmailValidation interface is minimal—implementations receive $extraData (useful for injecting config), but many built-in validators ignore it. Extend carefully.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle