yii2邮件配置教程,报Expected response code 250 but got code "553"原因
Posted 简庆旺的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘=>[‘[email protected]‘=>‘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‘ => ‘[email protected]‘
这样就能成功发送邮件了。
上面那个是配置supportEmail参数发出的邮件,下面这个是注释掉setFrom发出的邮件。
具体邮件内容的配置在common/mail目录下。
关于163邮箱的授权码:登录-》设置-》POP3/SMTP/IMAP-》按提示开启SMTP即可。
以上是关于yii2邮件配置教程,报Expected response code 250 but got code "553"原因的主要内容,如果未能解决你的问题,请参考以下文章
Laravel消息通知发送邮件 Expected response code 250 but got code "553", with message "553 Mail