首先明確下問題 是配置多個郵箱賬號來發送郵件。網上找了一堆資料 每一個說清楚的。
舉個例子,就是我有郵箱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;
}