Error:“Call to undefined method ping.” Using Yii2 and Swiftmailer

耗尽温柔 提交于 2021-01-29 09:53:00

问题


Any help would be highly appreciated.

I do not understand what I am doing wrong. I have used Swiftmailer before and it has never been this difficult to configure it.

I am using an advanced Yii2 project.

This is part of my backend/config/main.php (I have tried with backend/config/main-local.php, common/config/main.php and common/config/main-local.php just in case):

....
 'components' => [
 'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'localhost',
                'username' => 'name@example.com',
                'password' => 'password',
                'port' => '587',
                'encryption' => 'tls',
                'plugins' => [
                    [
                        'class' => 'Swift_Plugins_ThrottlerPlugin',
                        'constructArgs' => [20],
                    ],
                ],
            ],
        ],
....
],

This is part of my controller:

 public function actionTests()
    {  
    Yii::$app->mailer->compose()
            ->setFrom('name@example.com')
            ->setTo('name_2@example.com')
            ->setSubject('Email sent from Yii2-Swiftmailer')
            ->send();
    }

This is the error I am getting:

来源:https://stackoverflow.com/questions/56023790/errorcall-to-undefined-method-ping-using-yii2-and-swiftmailer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!