PHPackages                             harungecit/php-email-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. harungecit/php-email-validator

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

harungecit/php-email-validator
==============================

A comprehensive PHP email validation library to check format, detect disposable emails, validate MX records, and support batch validation.

2.0.0(5mo ago)311MITPHPPHP &gt;=7.4CI passing

Since Jan 22Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/harungecit/php-email-validator)[ Packagist](https://packagist.org/packages/harungecit/php-email-validator)[ Docs](https://github.com/harungecit/php-email-validator)[ RSS](/packages/harungecit-php-email-validator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

HarunGecit/php-email-validator
==============================

[](#harungecitphp-email-validator)

[![PHP Version](https://camo.githubusercontent.com/9efc6f0bd837905e4709934d35f38d91de321e9e03d37d46a97808cf41ef969a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f686172756e67656369742f7068702d656d61696c2d76616c696461746f723f7374796c653d666c61742d737175617265266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/harungecit/php-email-validator)[![Latest Version](https://camo.githubusercontent.com/33f3924ad9ee02075d1d698ef89db03b88cf102d93eb8d6fc7b6862d550c67e9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f686172756e67656369742f7068702d656d61696c2d76616c696461746f723f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465266c6162656c3d76657273696f6e)](https://packagist.org/packages/harungecit/php-email-validator)[![Total Downloads](https://camo.githubusercontent.com/9072321cd8ebe0c649ac00eeff3a8efa2182426f2d7eba9429aad91a2e076025/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686172756e67656369742f7068702d656d61696c2d76616c696461746f723f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/harungecit/php-email-validator)[![License](https://camo.githubusercontent.com/e4c5f674edb62157aef3153b843076fcee5d502829e4a028178723fa91bddcef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686172756e67656369742f7068702d656d61696c2d76616c696461746f723f7374796c653d666c61742d737175617265266c6f676f3d6f70656e736f75726365266c6f676f436f6c6f723d7768697465)](LICENSE)[![CI Status](https://camo.githubusercontent.com/7949e32cdcee89aade7954c4ae807a3930c75c7e9ebd88e146c276c5aa5ec9f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f686172756e67656369742f7068702d656d61696c2d76616c696461746f722f63692e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265266c6f676f3d676974687562266c6f676f436f6c6f723d7768697465266c6162656c3d7465737473)](https://github.com/harungecit/php-email-validator/actions)![Code Quality](https://camo.githubusercontent.com/d76554743a08a74c792f596c72b5e0bc2835fe5408ac19b16c7adb01a86cb42c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307175616c6974792d412d627269676874677265656e3f7374796c653d666c61742d737175617265266c6f676f3d636f64616379266c6f676f436f6c6f723d7768697465)![Maintenance](https://camo.githubusercontent.com/be65fcf3b08bf41d183a195d7e4ef697769e2de8ddf861525681c9ce1af19a46/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65642d7965732d677265656e3f7374796c653d666c61742d737175617265266c6f676f3d676974266c6f676f436f6c6f723d7768697465)

A comprehensive PHP email validation library for checking email format, detecting disposable email addresses, validating MX records, and batch email processing.

![Blocklist Domains](https://camo.githubusercontent.com/491ec98aaaabb31007c11194a02cbeab0e373bfb640499b6b81e20d3eb6c286c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f626c6f636b6c6973742d342c393030253242253230646f6d61696e732d7265643f7374796c653d666c61742d737175617265266c6f676f3d736869656c64266c6f676f436f6c6f723d7768697465)![Allowlist Domains](https://camo.githubusercontent.com/98947ee82a34de444505ee6e0c3e4d24c770f9e00a2115fc500dc08fbb08d013/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f616c6c6f776c6973742d313830253242253230646f6d61696e732d677265656e3f7374796c653d666c61742d737175617265266c6f676f3d736869656c64266c6f676f436f6c6f723d7768697465)![Platform Support](https://camo.githubusercontent.com/3011bed77eafd318a0caf818e91620721112f8c4f2ca77635f72353e55d40cb9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f706c6174666f726d2d4c696e757825323025374325323057696e646f77732532302537432532306d61634f532d626c75653f7374796c653d666c61742d737175617265266c6f676f3d77696e646f7773266c6f676f436f6c6f723d7768697465)

---

Features
--------

[](#features)

- **Format Validation:** Validates email addresses against RFC standards using PHP's built-in filters
- **Disposable Email Detection:** Identifies temporary/disposable email addresses using an extensive blocklist (4,900+ domains)
- **MX Record Validation:** Verifies the existence of mail servers for email domains
- **Batch Validation:** Validate multiple emails at once with detailed results
- **Statistics:** Get validation statistics for email lists
- **Filtering:** Filter valid/invalid emails from arrays
- **Customizable Lists:** Add/remove domains from blocklist and allowlist dynamically
- **Caching:** Built-in caching for improved performance
- **Lightweight:** All dependencies and blocklists included for offline use
- **Cross-Platform:** Works on Linux, Windows, and macOS

---

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require harungecit/php-email-validator
```

---

Compatibility
-------------

[](#compatibility)

This package is compatible with the following PHP versions:

- PHP 7.4
- PHP 8.0
- PHP 8.1
- PHP 8.2
- PHP 8.3
- PHP 8.4
- PHP 8.5

Tested on Ubuntu, Windows, and macOS platforms.

---

Quick Start
-----------

[](#quick-start)

```
use HarunGecit\EmailValidator\EmailValidator;

// Create validator with default lists
$validator = EmailValidator::create();

// Validate a single email
if ($validator->isValid('user@example.com')) {
    echo "Email is valid!";
}
```

---

Usage
-----

[](#usage)

### Basic Example

[](#basic-example)

```
use HarunGecit\EmailValidator\EmailValidator;
use HarunGecit\EmailValidator\Fetcher;

// Load blocklist and allowlist from the package
$blocklist = Fetcher::loadBlocklist();
$allowlist = Fetcher::loadAllowlist();

// Initialize the validator
$validator = new EmailValidator($blocklist, $allowlist);

$email = "example@10minutemail.com";

// Perform validations
if (!$validator->isValidFormat($email)) {
    echo "Invalid email format.";
} elseif ($validator->isDisposable($email)) {
    echo "Disposable email detected.";
} elseif (!$validator->hasValidMX($email)) {
    echo "Invalid MX record.";
} else {
    echo "Email is valid.";
}
```

### Complete Validation (One-liner)

[](#complete-validation-one-liner)

```
$validator = EmailValidator::create();

// Validates format, checks blocklist, and verifies MX records
if ($validator->isValid('user@example.com')) {
    echo "Email passed all checks!";
}

// Skip MX check for faster validation
if ($validator->isValid('user@example.com', false)) {
    echo "Email passed format and blocklist checks!";
}
```

### Detailed Validation Results

[](#detailed-validation-results)

```
$result = $validator->validateWithDetails('user@mailinator.com');

// Result structure:
// [
//     'valid' => false,
//     'format' => true,
//     'disposable' => true,
//     'mx' => null,
//     'domain' => 'mailinator.com',
//     'errors' => ['Disposable email address']
// ]

if (!$result['valid']) {
    foreach ($result['errors'] as $error) {
        echo "Error: $error\n";
    }
}
```

### Batch Validation

[](#batch-validation)

```
$emails = [
    'user1@gmail.com',
    'user2@mailinator.com',
    'invalid-email',
    'user3@example.com',
];

// Validate all emails at once
$results = $validator->validateMultiple($emails, false);

foreach ($results as $email => $result) {
    $status = $result['valid'] ? 'VALID' : 'INVALID';
    echo "$email: $status\n";
}
```

### Filter Valid/Invalid Emails

[](#filter-validinvalid-emails)

```
$emails = ['valid@gmail.com', 'bad@tempmail.com', 'invalid', 'ok@example.com'];

// Get only valid emails
$validEmails = $validator->filterValid($emails, false);
// Result: ['valid@gmail.com', 'ok@example.com']

// Get only invalid emails
$invalidEmails = $validator->filterInvalid($emails, false);
// Result: ['bad@tempmail.com', 'invalid']
```

### Get Validation Statistics

[](#get-validation-statistics)

```
$emails = ['a@gmail.com', 'b@tempmail.com', 'invalid', 'c@example.com'];

$stats = $validator->getStatistics($emails, false);

// Result:
// [
//     'total' => 4,
//     'valid' => 2,
//     'invalid' => 2,
//     'disposable' => 1,
//     'invalid_format' => 1,
//     'no_mx' => 0
// ]
```

### Custom Blocklist/Allowlist

[](#custom-blocklistallowlist)

```
$validator = new EmailValidator([], []);

// Add domains to blocklist
$validator->addToBlocklist('custom-disposable.com');
$validator->addMultipleToBlocklist(['temp1.com', 'temp2.com']);

// Add domains to allowlist (takes priority over blocklist)
$validator->addToAllowlist('allowed-domain.com');

// Remove domains
$validator->removeFromBlocklist('temp1.com');
$validator->removeFromAllowlist('allowed-domain.com');

// Get lists
$blocklist = $validator->getBlocklist();
$allowlist = $validator->getAllowlist();

// Get counts
echo "Blocklist: " . $validator->getBlocklistCount() . " domains\n";
echo "Allowlist: " . $validator->getAllowlistCount() . " domains\n";
```

### Email Normalization

[](#email-normalization)

```
// Normalize single email (lowercase, trim)
$normalized = $validator->normalize('  USER@EXAMPLE.COM  ');
// Result: 'user@example.com'

// Normalize multiple emails
$normalized = $validator->normalizeMultiple(['USER@A.COM', 'Test@B.Com']);
// Result: ['user@a.com', 'test@b.com']
```

### Extract Email Parts

[](#extract-email-parts)

```
$email = 'user.name+tag@sub.example.com';

$domain = $validator->extractDomain($email);
// Result: 'sub.example.com'

$localPart = $validator->extractLocalPart($email);
// Result: 'user.name+tag'
```

### Using Fetcher Utilities

[](#using-fetcher-utilities)

```
use HarunGecit\EmailValidator\Fetcher;

// Load both lists at once
$lists = Fetcher::loadAll();
$blocklist = $lists['blocklist'];
$allowlist = $lists['allowlist'];

// Load custom lists
$customBlocklist = Fetcher::loadCustomBlocklist('/path/to/custom.conf');

// Merge multiple lists
$merged = Fetcher::mergeLists(['/path/to/list1.conf', '/path/to/list2.conf']);

// Save a list
Fetcher::saveList('/path/to/output.conf', ['domain1.com', 'domain2.com']);

// Check file existence
if (Fetcher::blocklistExists()) {
    echo "Blocklist has " . Fetcher::getBlocklistCount() . " domains\n";
}

// Clear cache (useful for testing or reloading)
Fetcher::clearCache();
```

---

How It Works
------------

[](#how-it-works)

1. **Email Format Validation:**

    - Uses PHP's `filter_var` function with `FILTER_VALIDATE_EMAIL`
    - Example: `test@example.com` is valid, `test@com` is not
2. **Disposable Email Detection:**

    - Checks the domain against a blocklist of 4,900+ known disposable providers
    - Allowlist takes priority (domains in allowlist are never marked as disposable)
    - Example: `user@mailinator.com` is marked as disposable
3. **MX Record Validation:**

    - Uses `checkdnsrr` function to verify mail server existence
    - Results are cached for performance
    - Example: `example.com` with a valid mail server passes validation

---

Blocklist and Allowlist
-----------------------

[](#blocklist-and-allowlist)

The package comes with preloaded blocklist and allowlist files located in the `data/` directory.

- **Blocklist (`blocklist.conf`):** Contains 4,900+ domains of known disposable email providers
- **Allowlist (`allowlist.conf`):** Contains 180+ domains that should always be considered valid

### File Format

[](#file-format)

One domain per line, lowercase:

```
mailinator.com
guerrillamail.com
tempmail.com

```

You can customize these files or load custom lists using the Fetcher class.

---

API Reference
-------------

[](#api-reference)

### EmailValidator Class

[](#emailvalidator-class)

MethodDescription`create(): self`Static factory method with default lists`isValidFormat(string $email): bool`Validate email format`isDisposable(string $email): bool`Check if email is disposable`hasValidMX(string $email): bool`Check MX records`hasValidDNS(string $email): bool`Check A/AAAA records`isValid(string $email, bool $checkMX = true): bool`Complete validation`validateMultiple(array $emails, bool $checkMX = true): array`Batch validation`validateWithDetails(string $email, bool $checkMX = true): array`Detailed results`filterValid(array $emails, bool $checkMX = true): array`Filter valid emails`filterInvalid(array $emails, bool $checkMX = true): array`Filter invalid emails`getStatistics(array $emails, bool $checkMX = true): array`Get statistics`extractDomain(string $email): ?string`Extract domain`extractLocalPart(string $email): ?string`Extract local part`normalize(string $email): string`Normalize email`normalizeMultiple(array $emails): array`Normalize multiple`isAllowlisted(string $email): bool`Check if in allowlist`isBlocklisted(string $email): bool`Check if in blocklist`addToBlocklist(string $domain): self`Add to blocklist`addMultipleToBlocklist(array $domains): self`Add multiple to blocklist`addToAllowlist(string $domain): self`Add to allowlist`addMultipleToAllowlist(array $domains): self`Add multiple to allowlist`removeFromBlocklist(string $domain): self`Remove from blocklist`removeFromAllowlist(string $domain): self`Remove from allowlist`getBlocklist(): array`Get blocklist`getAllowlist(): array`Get allowlist`getBlocklistCount(): int`Get blocklist count`getAllowlistCount(): int`Get allowlist count`setCacheEnabled(bool $enabled): self`Enable/disable MX caching`clearCache(): self`Clear MX cache### Fetcher Class

[](#fetcher-class)

MethodDescription`loadBlocklist(bool $useCache = true): array`Load blocklist`loadAllowlist(bool $useCache = true): array`Load allowlist`loadAll(bool $useCache = true): array`Load both lists`loadCustomBlocklist(string $path): array`Load custom blocklist`loadCustomAllowlist(string $path): array`Load custom allowlist`mergeLists(array $paths): array`Merge multiple lists`saveList(string $path, array $domains): bool`Save list to file`clearCache(): void`Clear loaded cache`getBlocklistPath(): string`Get blocklist path`getAllowlistPath(): string`Get allowlist path`blocklistExists(): bool`Check blocklist exists`allowlistExists(): bool`Check allowlist exists`getBlocklistCount(): int`Get blocklist count`getAllowlistCount(): int`Get allowlist count---

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Run with coverage:

```
composer test-coverage
```

---

Upgrading from v1.x
-------------------

[](#upgrading-from-v1x)

If you're upgrading from v1.x, note these breaking changes:

1. **Namespace Change:**

    ```
    // Old (v1.x)
    use PHPOrbit\EmailValidator\EmailValidator;

    // New (v2.x)
    use HarunGecit\EmailValidator\EmailValidator;
    ```
2. **Package Name Change:**

    ```
    # Old
    composer require phporbit/php-email-validator

    # New
    composer require harungecit/php-email-validator
    ```

---

Contributing
------------

[](#contributing)

Contributions are welcome! To contribute:

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass
6. Submit a pull request

Please ensure that all new code:

- Has comprehensive tests
- Follows PSR-12 coding standards
- Includes PHPDoc comments

---

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

---

Author
------

[](#author)

**Harun Geçit**

- [GitHub](https://github.com/harungecit)
- [LinkedIn](https://linkedin.com/in/harungecit)
- [Email](mailto:info@harungecit.com)

---

Changelog
---------

[](#changelog)

### v2.0.0

[](#v200)

- **Breaking:** Namespace changed from `PHPOrbit\EmailValidator` to `HarunGecit\EmailValidator`
- **Breaking:** Package name changed from `phporbit/php-email-validator` to `harungecit/php-email-validator`
- Added batch email validation (`validateMultiple`, `filterValid`, `filterInvalid`)
- Added `isValid()` method for complete validation
- Added `validateWithDetails()` for detailed results
- Added `getStatistics()` for validation statistics
- Added static factory method `EmailValidator::create()`
- Added fluent interface for list management
- Added MX record caching with `setCacheEnabled()` and `clearCache()`
- Added `hasValidDNS()` for A/AAAA record checking
- Added email normalization methods
- Added `isAllowlisted()` and `isBlocklisted()` methods
- Enhanced Fetcher with caching, custom list loading, and merge capabilities
- Expanded test suite with comprehensive coverage
- Added multi-platform CI support (Ubuntu, Windows, macOS)
- Added PHP 8.5 support

### v1.0.2

[](#v102)

- Updated blocklist and allowlist files
- Improved code quality and documentation

### v1.0.1

[](#v101)

- Bug fixes and improvements

### v1.0.0

[](#v100)

- Initial release with support for:
    - Email format validation
    - Disposable email detection
    - MX record validation

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance73

Regular maintenance activity

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~164 days

Total

3

Last Release

154d ago

Major Versions

1.0.2 → 2.0.02025-12-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/cc3d4dec9b959b3d37e17003420b7ebbf4e6939eceeca2ef2205fe409e179c36?d=identicon)[harungecit](/maintainers/harungecit)

---

Top Contributors

[![harungecit](https://avatars.githubusercontent.com/u/37879288?v=4)](https://github.com/harungecit "harungecit (21 commits)")

---

Tags

disposabledisposable-emaildisposable-emailsemailemail-validatoremailvalidatorphpphp-disposable-emailphp-disposable-email-validatorvalidatorphpvalidatorvalidationemaildisposableemail-verificationemail validatorspam protectionblocklistallowlistmx-record

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/harungecit-php-email-validator/health.svg)

```
[![Health](https://phpackages.com/badges/harungecit-php-email-validator/health.svg)](https://phpackages.com/packages/harungecit-php-email-validator)
```

###  Alternatives

[egulias/email-validator

A library for validating emails against several RFCs

11.6k691.3M307](/packages/egulias-email-validator)[stymiee/email-validator

A robust PHP 7.4+ email validation library that extends beyond basic validation with MX record checks, disposable email detection, and free email provider validation. Features include strict typing, custom validator support, internationalization (i18n), and an extensible architecture. Perfect for applications requiring thorough email verification with customizable validation rules.

32426.6k1](/packages/stymiee-email-validator)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)[kartik-v/yii2-validators

Enhanced Yii2 model validator components / utilities for Yii2 Framework

21137.9k](/packages/kartik-v-yii2-validators)[martian/spammailchecker

A laravel package that protect users from entering non-existing/spam email addresses.

422.0k](/packages/martian-spammailchecker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
