paigejulianne/email-validator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

paigejulianne/email-validator

最新稳定版本:0.1.0

Composer 安装命令:

composer require paigejulianne/email-validator

包简介

A PHP library to validate email addresses, including syntax, MX record, and SMTP verification.

README 文档

README

A PHP Composer module for robust email address validation. This module performs comprehensive checks, including syntax validation, MX (Mail Exchange) record lookup, and SMTP (Simple Mail Transfer Protocol) server verification to ensure an email address is not only well-formed but also deliverable.

Features

  • Syntax Validation: Checks if the email address conforms to standard email format rules using filter_var(FILTER_VALIDATE_EMAIL).
  • MX Record Lookup: Determines if the domain of the email address has valid MX records, indicating it can receive mail.
  • SMTP Verification: Connects to the domain's SMTP server to verify if the email address is accepted for delivery.

Installation

To install this module, navigate to your project's root directory and run the following Composer command:

composer require paigejulianne/email-validator

Usage

To use the EmailValidator class, you first need to include the Composer autoloader. Then, instantiate the EmailValidator and call its validate method within a try-catch block to handle potential validation exceptions.

<?php

require_once __DIR__ . '/vendor/autoload.php';

use PaigeJulianne\EmailValidator\EmailValidator;
use PaigeJulianne\EmailValidator\Exceptions\EmailAddressFormatInvalid;
use PaigeJulianne\EmailValidator\Exceptions\EmailAddressHasNoMXRecords;
use PaigeJulianne\EmailValidator\Exceptions\EmailAddressUserDoesntExist;

$validator = new EmailValidator();

$emailsToValidate = [
    'test@example.com', // Domain with no MX records (often used for examples)
    'non-existent-email@gmail.com', // Syntactically correct but user doesn't exist
    'valid-email@gmail.com', // Replace with a real, valid email for actual testing
    'invalid-format', // Syntactically incorrect
];

foreach ($emailsToValidate as $email) {
    echo "Validating: {$email}\n";
    try {
        if ($validator->validate($email)) {
            echo "  Result: '{$email}' is a valid email address.\n\n";
        }
    } catch (EmailAddressFormatInvalid $e) {
        echo "  Result: '{$email}' is invalid (Format Invalid): {$e->getMessage()}\n\n";
    } catch (EmailAddressHasNoMXRecords $e) {
        echo "  Result: '{$email}' is invalid (No MX Records): {$e->getMessage()}\n\n";
    } catch (EmailAddressUserDoesntExist $e) {
        echo "  Result: '{$email}' is invalid (User Does Not Exist): {$e->getMessage()}\n\n";
    } catch (\Exception $e) {
        echo "  Result: An unexpected error occurred for '{$email}': {$e->getMessage()}\n\n";
    }
}

License

This project is licensed under the MIT License - see the LICENSE file for details (if one were to be created).

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-26