如何在yii2中使用Swift_Plugins_AntiFloodPlugin

时间:2016-09-30 02:22:17

标签: php yii2 swiftmailer

我发送了大约3000封带附件的电子邮件。出于这个原因,我使用swift邮件程序AntiFlood和Throttler插件。但是我收到了以下错误:

异常'yii \ base \ UnknownPropertyException',消息'设置未知属性:yii \ swiftmailer \ Mailer :: plugins'

这是我的main-local.php,我添加了插件。

        'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail',
        // send all mails to a file by default. You have to set
        // 'useFileTransport' to false and configure a transport
        // for the mailer to send real emails.
        'useFileTransport' => false,
        'transport' => [
                            'class'         => 'Swift_SmtpTransport',
                            'host'          => 'mail.test.com',
                            'username'      => 'noreply@test.com',
                            'password'      => 'welcome@123',
                            'port'          => '25',
                            //'encryption'    => 'tls',
                        ],
        'plugins'=> [
                        [
                            'class' => 'Swift_Plugins_ThrottlerPlugin',
                            'constructArgs' => ['20'],
                        ],
                        [
                             'class' => 'Swift_Plugins_AntiFloodPlugin',
                             'constructArgs' => [30,45],
                        ],
                    ],
    ],

谢谢

1 个答案:

答案 0 :(得分:2)

如上所述hereplugins密钥应位于transport内:

'mailer' => [
    'class' => 'yii\swiftmailer\Mailer',
    'viewPath' => '@common/mail',
    'useFileTransport' => false,
    'transport' => [
        'class'         => 'Swift_SmtpTransport',
        'host'          => 'mail.test.com',
        'username'      => 'noreply@test.com',
        'password'      => 'welcome@123',
        'port'          => '25',
        'plugins'=> [
            [
                'class' => 'Swift_Plugins_ThrottlerPlugin',
                'constructArgs' => ['20'],
            ],
            [
                'class' => 'Swift_Plugins_AntiFloodPlugin',
                'constructArgs' => [30,45],
            ],
        ],
    ],
],