2015-12-30 81 views

回答

2

對於通過Yii2發送電子郵件,您可以按照下面的步驟。

main.php

'mailer' => [ 
      'class' => 'yii\swiftmailer\Mailer', 


      'viewPath' => '@app/mail', 
      'useFileTransport' => false,//set this property to false to send mails to real email addresses 
      //comment the following array to send mail using php's mail function 
      'transport' => [ 
      'class' => 'Swift_SmtpTransport', 
      'host' => 'smtp.gmail.com', 
      'username' => 'email id', 
      'password' => 'password', 
      'port' => '587', 
      'encryption' => 'tls', 
      ], 

      ], 

控制器

\Yii::$app->mail->compose('your_view', ['params' => $params]) 
    ->setFrom([\Yii::$app->params['supportEmail'] => 'Test Mail']) 
    ->setTo('[email protected]') 
    ->setSubject('This is a test mail ') 
    ->send(); 

欲瞭解更多詳細信息,請參閱 Docs

-1

pop3協議僅用於從服務器獲取郵件不用於發送郵件!

但用於發送郵件,你可以使用默認的PHP的郵件功能

你可以閱讀更多在以下方面:

function.mail.php