欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

邮件配置教程,报Expected response code 250 but got code "553"原因 有大用

Expected response code 250 but got code "501", with message "501 mail from address must be same as authorization user

\Mail::send('front.emails.order',['hash_str'=>'hash_str','customer'=>'customer'],function($message) {
   $message->from('9581869@qq.com', '9581869@qq.com');//这一行加上去就好了,并且from后面的发件人邮箱和发件人名称必须一样
   $message->to('9509987957@qq.com');
});


image.png




邮件配置教程,报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即可。

来自  https://www.cnblogs.com/jianqingwang/p/6610032.html

普通分类: