错误:“调用未定义的方法ping。”使用Yii2和Swiftmailer

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: enter image description here

enter image description here

doufu8588
doufu8588 是。我正在发送一封电子邮件。
一年多之前 回复
douyun3022
douyun3022 你在发送一封电子邮件时收到此错误吗?
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐