Yii2 Mailer类将Swift Mailer动态配置移动到其他文件

时间:2018-09-21 17:16:49

标签: yii2 swiftmailer

通过我的Yii2应用程序,我试图弄清楚如何将前8行删除到一个更好的位置,以便可以保留Yii应用程序邮件程序类,并能够使用该设置发送电子邮件。

$transport = \Swift_SmtpTransport::newInstance('smtp.emailsrvr.com');
$mail = \Swift_Mailer::newInstance($transport);
$gen = EtsGeneral::find()->where(['GENERAL_ID' => 1])->one();

$mail->getTransport()
     ->setHost($gen->HOST)
     ->setUserName($gen->USERNAME)
     ->setPassword($gen->PASSWORD)
     ->setPort($gen->PORT);

$fromName = $gen->COMPANY;
$from = $gen->EMAIL;

Yii::$app->mailer->compose('transaction-failed', ['businessUnit' => $businessUnit, 'model' => $model])
         ->setFrom($from, $fromName)
         ->setTo($user->EMAIL)
         ->setSubject('Payment Transaction Failed')
         ->send();

0 个答案:

没有答案