imranali / verify-email
验证电子邮件是否存在
dev-master
2019-11-29 07:44 UTC
Requires
- php: >=7.0.0
- laravel/framework: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0.0
Requires (Dev)
- phpunit/phpunit: ^8.4@dev
This package is auto-updated.
Last update: 2024-09-29 05:42:24 UTC
README
这是一个简单的包,用于验证电子邮件是否存在。这对于希望从用户那里获取真实电子邮件地址的人来说非常有用。在注册用户、应用程序或新闻通讯时获取真实电子邮件地址。您还可以在向用户发送电子邮件之前检查电子邮件是否存在。这可以防止您的服务器被列入黑名单或发生硬退信。
- 避免硬退信
- 大多数公司购买SMTP电子邮件订阅,它们有有限的信用额度,您可以使用这个简单的包来节省电子邮件信用额度。
1. 要求
- Laravel 5.5.x 到 6.0.x
- PHP >= 7.0
2. 安装
-
使用composer要求此包
composer require imranali/verify-email -
将服务提供者添加到
config/app.php中的providersImranAli\VerifyEmail\VerifyEmailServiceProvider::class
并在
app/config.php中添加Facade作为别名'Verifyemail' => ImranAli\VerifyEmail\Facades\verifyEmailFacade::class,
Laravel 5.5 及以上版本使用包自动发现,因此您不需要手动注册服务提供者和Facade
-
发布配置
php artisan vendor:publish --provider="ImranAli\VerifyEmail\VerifyEmailServiceProvider"
3. 使用方法
您必须调用checkEmail()方法,它接受一个参数,即需要验证的电子邮件地址
Verifyemaill::checkEmail('test@example.com');
如果电子邮件存在,则返回true,否则返回false
此包包含一些配置,您可以相应地更改设置。配置包含一个字段from_email,请确保设置有效的电子邮件地址,因为此电子邮件地址将用于发送请求。
您还可以在运行时设置电子邮件,例如使用Facade
Verifyemail::setEmailFrom('support@domain.com');
它还有一个辅助方法,可以用于验证电子邮件地址模式
Verifyemail::validate('example@domain.com')
以下是完整的示例代码
// can also be set email at runtime (optional), it is good to set in config file Verifyemail::setEmailFrom('support@domain.com'); // email address to check $email = 'exampl@domain.com'; if (Verifyemail::checkEmail($email)) { echo 'email <' . $email . '> exist!'; } elseif (Verifyemail::validate($email)) { echo 'email <' . $email . '> valid, but not exist!'; } else { echo 'email <' . $email . '> not valid and not exist!'; }