2015-12-24 180 views
0

任何知道如何發送驗證到用戶成功後在系統上註冊他們的信息驗證電子郵件....我希望任何人都可以一步一步解釋....我應該編輯或有任何解決方案或建議:Yii2發送驗證到電子郵件

Yii::$app->mail->compose() 
->setFrom('[email protected]') 
->setTo('[email protected]') 
->setSubject('Email sent from Yii2-Swiftmailer') 
->send(); 

我已經配置這樣的swiftmailer:

'mail' => [ 
     'class' => 'yii\swiftmailer\Mailer', 
     'transport' => [ 
      'class' => 'Swift_SmtpTransport', 
      'host' => 'localhost', 
      'username' => 'username', 
      'password' => 'password', 
      'port' => '587', 
      'encryption' => 'tls', 
     ], 

回答

0

您應該使用配置「郵件」而不是「郵件」這樣 設置'useFileTransport' => false

並且在這種情況下爲您的郵件服務器設置傳輸是gmail 如果您使用其他郵件服務器,則必須正確設置相關參數。

'components' => [ 
     ......... 
     'mailer' => [ 
     'class' => 'yii\swiftmailer\Mailer', 
     'viewPath' => '@common/mail', 
     // send all mails to a file by default. You have to set 
     // 'useFileTransport' to false and configure a transport 
     // for the mailer to send real emails. 
     //'useFileTransport' => true, 
     '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 protected]', 
      'password' => 'yourpassword', 
      'port' => '587', 
      'encryption' => 'tls', 
     ], 
    ], 
+0

ok..i本來就this..then如何發送驗證註冊 – zack

+0

成功後通過電子郵件發送。如果你沒有特殊需要最好使用用戶擴展像http://www.yiiframework.com/extension/yii2-user-management /這些擴展包含了你需要的所有功能,包括確認郵件和其他許多useuf功能 – scaisEdge

+0

端口587實際上是爲了什麼..did它有其他端口.. – zack