Yii2如何配置多个邮箱来进行发送

首先明确下问题 是配置多个邮箱账号来发送邮件。网上找了一堆资料 每一个说清楚的。
举个例子,就是我有邮箱A 和邮箱B, 想根据不同的业务场景来选择对应的邮箱来作为发件人

 public function actionSend()
    {
        $mailer = Yii::$app->mailer;

        $mailer_config = [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.gmail.com',
                'username' => '[email protected]',
                'password' => 'xxxxxx',
                'port' => 587,
                'encryption' => 'tls',//tls or ssl
            ];

        $mailer->transport = $mailer_config;
#注意,需要在config文件夹下的params文件中配置文章开始的mailer项
        $sender = $mailer->compose('test', ['content' => '111'])
            ->setSubject('xxxxxx')
            ->setFrom('[email protected]')
            ->setTo('[email protected]')
            ->send();
        return true;

    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章