Yii2 Mailer实际上并没有发送电子邮件

时间:2016-11-01 12:35:22

标签: yii2 html-email swiftmailer

我按照 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,]);
        }  

1 个答案:

答案 0 :(得分:0)

您的配置需要额外的课程:

INSERT