Yii2 mail configuration tutorial, reported Expected response code 250 but got code "553" reason, yii2expected
The mail configuration in main. php (or main-local.php) is as follows:
'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 to send an email. true means that the generated email is in the runtime folder, do not send an email 'Port' => ['class' => 'SWIFT _ SmtpTransport ', 'host' => 'smtp .163.com ', // The host configuration for each mailbox is different: 'username' => 'zhong _ mail_test ', 'Password' => '**********', // 163 authorization code 'Port' => '25', 'encryption' => 'tls ',], 'messageconfig' => ['charset' => 'utf-8', 'from' => ['zhong _ mail_test@163.com '=> 'zhong-mail'],],
The code for sending an email is as follows:
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();
As shown in the preceding configuration, the following message is displayed:
Expected response code 250 but got code "553", with message "553 Mail from must equal authorized user
"
This is because some email servers require the from and username to be consistent, and the 163 mailbox is like this.
To avoid this problem, we can remove the setFrom setting in the sending code, or configure the supportEmail parameter in param. php (or param-local.php:
'supportEmail' => 'zhong_mail_test@163.com'
In this way, the email is successfully sent.
The above is the email sent by configuring the supportEmail parameter. below is the email sent by the setFrom annotation.
The specific mail content is configured in the common/mail directory.
For the authorization code of 163 mail, go to logon> Settings> POP3/SMTP/IMAP, and follow the prompts to enable SMTP.