drq1257 2017-06-10 18:35 采纳率: 0%
浏览 121
已采纳

我们如何在yii 2中通过电子邮件实现密码恢复

I tried to do some changes in common/config/main-local.php

'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.mailtrap.io',
                'username' => 'example@examplemail.com',
                'password' => '***************',
                'port' => '2525',
                'encryption' => 'tls',
            ],
        ],
  • 写回答

1条回答 默认 最新

  • douhuai2861 2017-06-11 10:14
    关注

    Maybe some of your transport settings are incorrect, so it cannot send an email. For local server you can just set useFileTransport to true like:

    'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        // 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' => true,
    ],
    

    Then check your <app>/runtime/mail/folder, where *.eml mail will be generated. Therefore you can click on your password-recovery link and proceed futher.

    P.S. Yii2 advanced template includes email password-recovery feature from the box (if you are implementing it from scratch)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?