ylly/mailboxlayerbundle

ylly/mailboxlayer的Symfony扩展包

安装: 34

依赖: 0

建议者: 0

安全: 0

星星: 1

关注者: 4

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.1 2018-09-27 09:17 UTC

This package is auto-updated.

Last update: 2024-09-09 23:21:20 UTC


README

步骤 1 : 下载扩展包

打开命令行控制台,进入您的项目目录,并执行以下命令以下载此扩展包的最新稳定版本

$ composer require ylly/mailboxlayerbundle

此命令要求您全局安装了Composer,如Composer文档的安装章节所述。

步骤 2 : 启用扩展包

然后,通过将其添加到项目app/AppKernel.php文件中注册的扩展包列表来启用扩展包

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Ylly\Bundle\MailboxLayer\YllyMailboxLayerBundle(),
        );
    }
}

步骤 3 : 生成访问密钥

您需要在mailchimp层生成一个密钥,并将其添加到config.yml中

https://mailchimp.com/product

然后,将其添加到项目的app/config/config.yml文件中

ylly_mailbox_layer:
  access_key: generated access key from mailboxLayer 

对于最大配置(并且在使用您自己的代理或monolog扩展包的情况下),有一些配置参数您可以修改。

默认情况下,显示消息的级别为200(即INFO)和通道为app。有关更多信息,请参阅:https://symfony.com.cn/doc/current/logging.html

ylly_mailbox_layer:
  access_key: generated access key from mailboxLayer 
  proxy: null
  monolog_level: 200
  monolog_channel: app

步骤 4 : 使用

为了允许电子邮件验证,ylly/mailboxLayerBundle使用一个非常简单的断言(或约束),它可以应用于任何电子邮件的属性。

<?php

namespace App\Bundle\YourBundle\YourEntity;

use Ylly\Bundle\MailboxLayer\Validator\Constraints as MailboxLayerAssert;

class User
{
    /**
    * @var string
    * @MailboxLayerAssert\MailboxLayer
    */
    private $email;
}

步骤 5 : 可选

您可以对一些选项进行微调以执行电子邮件验证

  • CheckMx验证电子邮件地址是否有MX记录。

  • CheckSmtp验证SMTP请求是否由服务器处理。

  • CatchAll检查请求的电子邮件地址是否是catch-all邮箱的一部分。警告!catchAll选项只能由mailchimp的专业账户使用。默认为false。

  • RefuseDisposable检查电子邮件地址不是临时地址。如果要设置true,则表示您不希望使用临时地址。默认为false。

  • RefuseUnderScore检查电子邮件地址的质量评分。如果不想电子邮件的评分低于所选限制,允许在0到1之间浮点。默认为0。

  • SkipIfServerErrors。当为true时,此选项允许电子邮件在mailchimp层API关闭或存在用户权限问题时通过验证。默认为true。

<?php
 
 namespace App\Bundle\YourBundle\YourEntity;
 
 use Ylly\Bundle\MailboxLayer\Validator\Constraints as MailboxLayerAssert;
 
 class User
 {
     /**
     * @var string
     * 
     * @MailboxLayerAssert\MailboxLayer(
     * checkMx = true, 
     * checkSmtp = true, 
     * isCatchAll = false,
     * refuseDisposable = false,
     * refuseUnderScore = 0,
     * skipIfServerErrors = true
     * )
     */
     private $email;
 }

步骤 6 : 记录器

如果您使用的是Symfony/Monolog-Bundle,ylly/mailboxlayerbundle提供了一种在验证接受时记录电子邮件的方式,尽管存在服务器错误(请参阅步骤 5:可选:SkipIfServerErrors)。

如果您使用的是其他记录器接口,您可以在services_logger.yml文件中使用标签'ylly.logger'实现自己的Logger类并添加Logger服务。

信息提供

有关ylly/mailboxMailer库的更多信息,该库由ylly/mailboxlayerbundle实现

https://github.com/ylly/mailboxlayer