2016-11-01 4 views
0

나는Yii2 메일러 실제로 전송되지 않은 이메일

https://www.youtube.com/watch?v=c5pebmTUQjs&index=21&list=PLRd0zhQj3CBmusDbBzFgg3H20VxLx2mkF

첨부 파일, 로 이메일을 보내기위한 Yii2 튜토리얼 (당신이 필요하면 아래의 링크를 참조)을 따라 그리고 그것은 일 시스템이 전송하려는 전자 메일 정보와 첨부 파일을 읽은 다음 db에 정보 및 첨부 파일 링크를 저장하는 수준입니다. YII \ 기본 \의 InvalidConfigException 알 수없는 설정 -

잘못된 구성 : 내가 진짜 수신자에게 이메일을 보내려고하고 메일러 설정을 변경할 때

는하지만, 다음 문제가 발생했습니다 새 전자 메일 을 만들려고 특성 : Swift_MailTransport :: 호스트 여기

는 우편물에 대한 설정입니다 :

'mailer' => [ 
    'class' => 'yii\swiftmailer\Mailer', 
    'viewPath' => '@app/mail', 
    'useFileTransport' => false, 
    'transport' => [ 
        'host' => 'smtp.live.com', 
        'username' => '[email protected]', 
        'password' => 'password', 
        'port' => '587', 
        'encryption' => 'tls', 
        ] 
], 

을 그리고 여기에 A는 EmailsController의 ctionCreate 부분 :

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 (['[email protected]'=>'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 (['[email protected]'=>'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,]); 
     } 

답변

0

귀하의 구성이 추가 클래스를 필요 :

'mailer' => [ 
    'class' => 'yii\swiftmailer\Mailer', 
    'viewPath' => '@app/mail', 
    'useFileTransport' => false, 
    'transport' => [ 
     'class' => 'Swift_SmtpTransport', // <-- here 
     'host' => 'smtp.live.com', 
     'username' => '[email protected]', 
     'password' => 'password', 
     'port' => '587', 
     'encryption' => 'tls', 
    ] 
], 
+0

나는 많은 참조를보고 포함 다른 클래스가 없었다. 그리고 정말로 다른 반을 필요로한다면, 그것이 무엇 이냐, 그것이 무엇을 의미할까요? 문서 링크를 참조하십시오 : http://www.yiiframework.com/doc-2.0/yii-swiftmailer-mailer.html –

+0

기본적으로 'Swift_MailTransport'가 사용됩니다. 이것은 [여기] (http://swiftmailer.org/docs/sending.html)에 명시된 SwiftMailer의 Transport 클래스입니다. 이 메일은 [Mailer] (https://github.com/yiisoft/yii2-swiftmailer/blob/master/Mailer.php) 클래스의 yii2-swiftmailer 확장 프로그램에서 볼 수 있습니다. – Bizley