plumpboy / email-validate
一个通过SMTP验证电子邮件的库,继承自 https://github.com/semplon/php-smtp-email-validation
v1.1.4
2021-01-08 07:52 UTC
Requires
- php: >=5.5
- egulias/email-validator: ^2.0
- swiftmailer/swiftmailer: ^6.2
This package is not auto-updated.
Last update: 2024-09-28 23:21:46 UTC
README
一个扩展自 https://github.com/semplon/php-smtp-email-validation 的库
它能做什么?
通过SMTP检查电子邮件地址是否存在。
要求
- php >= 5.5
安装
- composer require plumpboy/email-validate
用法
... use Plumpboy\EmailValidate\SMTPEmailValidator; ... // the email to validate $email = 'user@example.com'; // $email can be array('user@example.com', 'user1@example.com') // an optional sender $sender = 'user@mydomain.com'; // instantiate the class $SMTPValidator = new SMTPEmailValidator(); // turn on debugging if you want to view the SMTP transaction $SMTPValidator->debug = true; // do the validation $results = $SMTPValidator->validate($email, $sender); // view results echo $email.' is '.($results ? 'valid' : 'invalid')."\n"; // $results[$email] when there are many emails // send email? if ($results) { // or $results['user@example.com'] if you pass many emails //mail($email, 'Confirm Email', 'Please reply to this email to confirm', 'From:'.$sender."\r\n"); // send email } else { echo 'The email addresses you entered is not valid'; }
Laravel
对于使用laravel版本 < 5.5 的项目,将以下代码添加到 config/app.php。
... 'providers' => [ ... Plumpboy\EmailValidate\EmailValidateServiceProvider::class, ... ], ...
你还可以在laravel中使用以下语法。
$result = email_exists($emails, $sender); // use helper
... use Plumpboy\EmailValidate\EmailValidator; ... $result = EmailValidator::validate($email, $sender); // use facade
$result = \EmailValidator::validate($email, $sender); // or alias
如果没有传递参数 $sender,库将使用 config('mail.from.address')
。
贡献
- 从仓库分叉并对你分叉的分支进行更改。
- 提交信息必须以大写字母和简短的摘要开头。
- 每次提交后,确保测试套件通过。
- 贡献者向 release/develop 分支发送 pull request,并请另一位贡献者检查是否可行。
- 不要将私钥、日志或任何不必要的文件推送到 git 仓库
- 当 pull request 获得两个 OK 并且 CI 构建为绿色时进行合并。
- 将 develop 合并到 master 以发布最终版本。