Yii2 swiftmailer Expected response code 220 but got code "502", with message "502 Error:

按照教程使用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搭建的开发环境,具体原因,希望有人能找到。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值