2015-12-24 146 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