有知道怎么用dektrium/yii2-user这个扩展的吗?注册后验证邮件发送失败 [ 2.0 版本 ]
配置好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'],
],
],
]
]
最佳答案
-
这是反垃圾邮件系统约束条件,
501 mail from address must be same as authorization user
已经讲得很清楚了。修改一下
Mailer.php
的sendMessage()
函数中的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(); } }
其他 2 个回答
-
我的设置,首先我用的是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
注册时间:2015-09-24
最后登录:2016-04-17
在线时长:31小时2分
最后登录:2016-04-17
在线时长:31小时2分
- 粉丝2
- 金钱2402
- 威望0
- 积分2712