Yii2 mail configuration tutorial, report Expected response code 250 but got code & quot; 553 & quot; reason, yii2expected

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.