zytzagoo / smtp-validate-email
通过SMTP进行电子邮件地址验证
Requires
- php: >=7.2||>=8
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-12 18:16:27 UTC
README
通过SMTP进行电子邮件地址验证/验证。
SMTPValidateEmail\Validator
类检索电子邮件域的MX记录,然后连接到域的SMTP服务器以尝试确定地址是否确实存在。
早期版本(1.0之前)使用的是SMTP_Validate_Email
类名(且未使用命名空间和其他现在常见的PHP特性)。已经注意保留旧的API,迁移旧代码应该不会痛苦。请参阅"从旧版本迁移到1.0"部分。或者直接使用/下载古老的0.7版本。
特性
- 实际上不发送消息,完成时优雅地重置SMTP会话
- 根据相关的RFC实现了命令特定的通信超时
- 支持捕获所有账户检测
- 支持批处理模式处理
- 支持日志/调试
- 无外部依赖
- 由单元/功能测试覆盖
安装
通过composer安装
composer require zytzagoo/smtp-validate-email --update-no-dev
使用示例
基本示例
<?php require 'vendor/autoload.php'; use SMTPValidateEmail\Validator as SmtpEmailValidator; /** * Simple example */ $email = 'someone@example.org'; $sender = 'sender@example.org'; $validator = new SmtpEmailValidator($email, $sender); // If debug mode is turned on, logged data is printed as it happens: // $validator->debug = true; $results = $validator->validate(); var_dump($results); // Get log data (log data is always collected) $log = $validator->getLog(); var_dump($log);
多个收件人和其他详细信息
<?php require 'vendor/autoload.php'; use SMTPValidateEmail\Validator as SmtpEmailValidator; /** * Validating multiple addresses/recipients at once: * (checking multiple addresses belonging to the same server * uses a single connection) */ $emails = [ 'someone@example.org', 'someone.else@example.com' ]; $sender = 'sender@example.org'; $validator = new SmtpEmailValidator($emails, $sender); $results = $validator->validate(); var_dump($results); /** * The `validate()` method accepts the same parameters * as the constructor, so this is equivalent to the above: */ $emails = [ 'someone@example.org', 'someone.else@example.com' ]; $sender = 'sender@example.org'; $validator = new SmtpEmailValidator(); $results = $validator->validate($emails, $sender); var_dump($results);
从旧版本迁移到1.0
早期版本使用的是全局SMTP_Validate_Email
类名。您可以在现有代码中继续使用该名称,并通过使用别名/导入切换到较新的(由composer支持的)版本,如下所示
需要composer包
composer require zytzagoo/smtp-validate-email --update-no-dev
然后在您的代码中
<?php require 'vendor/autoload.php'; use SMTPValidateEmail\Validator as SMTP_Validate_Email; // Now any old code referencing `SMTP_Validate_Email` should still work as it did earlier
开发 & 贡献
请参阅Makefile和composer.json中的开发依赖项。
在克隆(或下载)存储库后运行make
会为您提供
Usage: make [target]
[target] help
-------- ----
help What you're currently reading
install Installs dev dependencies
clean Removes installed dev dependencies
test Runs tests
coverage Runs tests with code coverage
server-start Stops and starts the smtp server
server-stop Stops smtp server if it's running
(PIDFILE) Starts the smtp server
(MAILHOG) Downloads platform-specific mailhog binary
因此,运行make install
以开始。之后您应该能够运行测试(make test
)。
测试由phpunit
和本地运行在1025端口的./bin/mailhog
实例提供支持。需要SMTP服务器的测试被标记为跳过(如果SMTP服务器不可用)。
欢迎提交拉取请求!
为了使您的拉取请求被合并,请遵循以下简单的规则
- 所有代码提交都必须通过
make test
无错误地通过 - 遵循现有的代码风格(使用
phpcs
) - 不应有外部依赖
- 如果您想添加重要的功能/依赖项,首先提交一个关于此的issue,以便我们可以讨论添加是否适合项目