首页 > 代码库 > yii2邮件配置教程,报Expected response code 250 but got code "553"原因
yii2邮件配置教程,报Expected response code 250 but got code "553"原因
main.php(或main-local.php)中的邮件配置如下:
‘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,//false发送邮件,true只是生成邮件在runtime文件夹下,不发邮件 ‘transport‘ => [ ‘class‘ => ‘Swift_SmtpTransport‘, ‘host‘ => ‘smtp.163.com‘, //每种邮箱的host配置不一样 ‘username‘ => ‘zhong_mail_test‘, ‘password‘ => ‘**********‘,//163邮箱的授权码 ‘port‘ => ‘25‘, ‘encryption‘ => ‘tls‘, ], ‘messageConfig‘=>[ ‘charset‘=>‘UTF-8‘, ‘from‘=>[‘zhong_mail_test@163.com‘=>‘zhong-mail‘] ],],
发送邮件的代码如下:
return Yii::$app ->mailer ->compose( [‘html‘ => ‘passwordResetToken-html‘, ‘text‘ => ‘passwordResetToken-text‘], [‘user‘ => $user] ) ->setFrom([Yii::$app->params[‘supportEmail‘] => Yii::$app->name . ‘ robot‘]) ->setTo($this->email) ->setSubject(‘Password reset for ‘ . Yii::$app->name) ->send();
如就按照上述配置会报:
Expected response code 250 but got code "553", with message "553 Mail from must equal authorized user
"
这是因为有些邮件服务器要求from和username必须一致,163邮箱就是这样。
为避免这个问题,我们可以将发件代码中的setFrom设置去掉,或者在param.php(或param-local.php)中配置supportEmail参数:
‘supportEmail‘ => ‘zhong_mail_test@163.com‘
这样就能成功发送邮件了。
上面那个是配置supportEmail参数发出的邮件,下面这个是注释掉setFrom发出的邮件。
具体邮件内容的配置在common/mail目录下。
关于163邮箱的授权码:登录-》设置-》POP3/SMTP/IMAP-》按提示开启SMTP即可。
yii2邮件配置教程,报Expected response code 250 but got code "553"原因
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。