【发布时间】:2016-11-01 12:35:22
【问题描述】:
我按照 Yii2 教程来发送带附件的电子邮件, (如果需要,请参阅下面的链接)
https://www.youtube.com/watch?v=c5pebmTUQjs&index=21&list=PLRd0zhQj3CBmusDbBzFgg3H20VxLx2mkF
它在系统读取我要发送的电子邮件信息和附件并将信息和附件链接保存在数据库中的级别上工作。
但是当我尝试向真实收件人发送电子邮件并更改邮件配置时,然后尝试创建新电子邮件 有问题:
无效配置 – yii\base\InvalidConfigException 设置未知属性:Swift_MailTransport::host
这是邮件程序的配置:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@app/mail',
'useFileTransport' => false,
'transport' => [
'host' => 'smtp.live.com',
'username' => 'username@live.com',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
]
],
这里是 EmailsController 的 actionCreate 部分:
public function actionCreate()
{
$model = new Emails();
if ($model->load(Yii::$app->request->post()))
{
$model->attachment= UploadedFile::getInstance($model,'attachment');
if ($model->attachment)
{
$time=time();
$model->attachment->saveAs ('attachments/' .$time.'.' .$model->attachment->extension);
$model->attachment='attachments/'.$time.'.'.$model->attachment->extension;
}
if ($model->attachment)
{
$value= Yii::$app->mailer->compose()
->setFrom (['sharqpress@hotmail.com'=>'Al-Sharq Printing Press'])
->setTo ($model->reciever_email)
->setSubject ($model->subject)
->setHtmlBody ($model->content)
->attach ($model->attachment)
->send();
}
else
{
$value= Yii::$app->mailer->compose()
->setFrom (['sharqpress@hotmail.com'=>'Al-Sharq Printing Press'])
->setTo ($model->reciever_email)
->setSubject ($model->subject)
->setHtmlBody ($model->content)
->send();
}
$model->save();
return $this->redirect(['view','id'=>$model->id]);}
else
return $this -> render('create',['model'=>$model,]);
}
【问题讨论】:
标签: yii2 html-email swiftmailer