按照教程使用yii2的发邮件功能,在配置问题件配置如下
'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' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.163.com',
'username' => '***@163.com',
'password' => '***', //此处填写授权码,而不是密码
'port' => '25',
'encryption' => 'tls',
],
使用Yii2的邮箱,出现两种报错,
1. 报错:Expected response code 250 but got code "553"
主要原因是,密码配置错误,填写的是邮箱密码,而不是授权码。如果不明白的,可以到http://www.yii-china.com/post/detail/10.html里查看教程设置。
2.出现:Expected response code 220 but got code "502"
无论如何设置都是报错,后来看到(http://blog.csdn.net/marswill/article/details/69388360)提到的encyption配置问题,然后将配置信息改成如下,没想到竟然不报错了。
'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' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.163.com',
'username' => '***@163.com',
'password' => '****',
'port' => '465/994',
'encryption' => 'ssl',
],
可能是环境的问题。我的是wamp搭建的开发环境,具体原因,希望有人能找到。