2015-10-09 20:59:31 8487次浏览 3条回答 2 悬赏 20 金钱

配置好mailer,自己写controller能够发出邮件,我用的163和qq邮件都成功。但是用yii2-user注册后显示_Swift_TransportException Expected response code 250 but got code "501", with message "501 mail from address must be same as authorization user_。不知道怎么回事.我已经配置了模块

'modules' => [
    'user' => [
        'class' => 'dektrium\user\Module',
        'enableUnconfirmedLogin' => true,
        'confirmWithin' => 21600,
        'cost' => 12,
        'admins' => ['admin'],
             ],     
        ],
    ]
]

最佳答案

  • 性感的农民 发布于 2015-10-09 22:25 举报

    这是反垃圾邮件系统约束条件,501 mail from address must be same as authorization user 已经讲得很清楚了。

    修改一下Mailer.phpsendMessage()函数中的setFrom($this->sender)语句的参数,改成和你配置mailer时用的邮件地址一样即可。

        /**
         * @param string $to
         * @param string $subject
         * @param string $view
         * @param array  $params
         *
         * @return bool
         */
        protected function sendMessage($to, $subject, $view, $params = [])
        {
            /** @var \yii\mail\BaseMailer $mailer */
            $mailer = Yii::$app->mailer;
            $mailer->viewPath = $this->viewPath;
            $mailer->getView()->theme = Yii::$app->view->theme;
            if ($this->sender === null) {
                $this->sender = isset(Yii::$app->params['adminEmail']) ? Yii::$app->params['adminEmail'] : 'no-reply@example.com';
            }
            return $mailer->compose(['html' => $view, 'text' => 'text/' . $view], $params)
                ->setTo($to)
                ->setFrom($this->sender)
                ->setSubject($subject)
                ->send();
        }
    }
    
    , 觉得很赞
  • 回答于 2016-04-08 18:21 举报

    在config目录下的params.php
    adminEmail的设置也要修改。

    , , 觉得很赞
  • 回答于 2018-04-26 07:25 举报

    我的设置,首先我用的是basic版
    在config/web.php中
    /*'user' => [

            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
    

    */将原来的user注释掉,
    在components中添加:
    'mailer' => [

            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@app/mailer',
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.163.com',
                'username' => 'xxxx@163.com',
                'password' => "xxxx",
                'port' => '587',   //你也可以试试994 、465这些端口
                'encryption' => 'ssl',
            ],
    

    然后在components外添加:
    'modules' => [

        'user' => [
            'class' => 'dektrium\user\Module',
            'enableUnconfirmedLogin' => true,
            'confirmWithin' => 21600,
            'cost' => 12,
            'admins' => ['admin']
        ],
    ],
    

    在config/param.php中
    //'adminEmail' => 'admin@example.com', 改为

    'adminEmail' =>'xxxx@163.com',
    
您需要登录后才可以回答。登录 | 立即注册
aoyo
总监

aoyo

注册时间:2015-09-24
最后登录:2016-04-17
在线时长:31小时2分
  • 粉丝2
  • 金钱2402
  • 威望0
  • 积分2712

热门问题