Home > Backend Development > PHP Tutorial > YII2邮件配置,网上方法不凑效!

YII2邮件配置,网上方法不凑效!

WBOY
Release: 2016-06-06 20:36:25
Original
1273 people have browsed it

先上我的配置项

<code>'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail',
        'useFileTransport' => true,
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.163.com',
            'username' => 'username@163.com',
            'password' => 'myPassword',
            'port' => '994',
            'encryption' => 'ssl',
        ],
    ],
</code>
Copy after login
Copy after login

然后上我的发送代码

<code>return \Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])
    ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])
    ->setTo($this->email)
    ->setSubject('Password reset for ' . \Yii::$app->name)
    ->send();
</code>
Copy after login
Copy after login

怎么测试都无效,是不是我姿势不对?!

回复内容:

先上我的配置项

<code>'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail',
        'useFileTransport' => true,
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.163.com',
            'username' => 'username@163.com',
            'password' => 'myPassword',
            'port' => '994',
            'encryption' => 'ssl',
        ],
    ],
</code>
Copy after login
Copy after login

然后上我的发送代码

<code>return \Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])
    ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])
    ->setTo($this->email)
    ->setSubject('Password reset for ' . \Yii::$app->name)
    ->send();
</code>
Copy after login
Copy after login

怎么测试都无效,是不是我姿势不对?!

'useFileTransport' => true,

改为false ,如果是true只是生成邮件 在runtime下

我觉得Yii2目前还不是很稳定。现在还暂时不能用于生产环境

好像\Yii::$app->mailer的setFrom()设置的邮箱应该和配置里的邮箱一致才能发。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template