首页 文章

Laravel 5重置密码通知将不会发送

提问于
浏览
4

我正在尝试在我的应用程序中实现默认的重置密码通知,但是当我尝试进行密码重置时,没有任何反应只会说“我们已经通过电子邮件发送了密码重置链接!”但是当我尝试检查我的邮箱时,我的应用程序没有发送任何电子邮件 .

我在我的应用程序上做了所有必要的配置:电子邮件驱动程序,数据库设置

但是Laravel的某些部分我做了改变:用户模型,用户表迁移

表格列我改变了 .

id,name,US_EMAIL,密码,remember_token,created_at,updated_at,EMP_POSITION,FACTORY,CONTACT,SIGNATURE,ONLINE,DATE_ONLINE,ADMIN,LOCK

我在重置密码表上没有做任何操作,默认的laravel迁移中所有字段都是完整的 .

当我尝试调试我的应用程序时,似乎当我尝试重置密码时,应用程序可以成功将数据保存到“password_resets”表,但我仍然无法接收电子邮件重置通知 .

我也确实看过这个特性,我试图“转储和死亡”,看看我点击“发送密码重置链接”后进程的位置,似乎应用程序仍然可以继续这个特性,因为它仍然显示“dd”信息 .

<?php

namespace Illuminate\Auth\Passwords;

use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification;

trait CanResetPassword
{
    /**
     * Get the e-mail address where password reset links are sent.
     *
     * @return string
     */
    public function getEmailForPasswordReset()
    {
        return $this->EMAIL;
    }

    /**
     * Send the password reset notification.
     *
     * @param  string  $token
     * @return void
     */
    public function sendPasswordResetNotification($token)
    {
        dd('Test SendPasswordNotification');
        $this->notify(new ResetPasswordNotification($token));
    }
}

我也确实看过这个但是当我试图“转储并死”到“toMail”功能时它没有继续 . 我想也许应用程序不会发送电子邮件,因为它不能进入这个课程,我只是猜测,但我希望有人可以帮我这个 .

<?php

namespace Illuminate\Auth\Notifications;

use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;

class ResetPassword extends Notification
{
    /**
     * The password reset token.
     *
     * @var string
     */
    public $token;

    /**
     * Create a notification instance.
     *
     * @param  string  $token
     * @return void
     */
    public function __construct($token)
    {
        $this->token = $token;
    }

    /**
     * Get the notification's channels.
     *
     * @param  mixed  $notifiable
     * @return array|string
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Build the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
      dd('Test ToMail');
        return (new MailMessage)
            ->line('You are receiving this email because we received a password reset request for your account.')
            ->action('Reset Password', route('password.reset', $this->token))
            ->line('If you did not request a password reset, no further action is required.');
    }
}

更新:我可以使用我的.env电子邮件设置发送电子邮件,我认为应用程序可以对我使用的电子邮件服务器进行身份验证 . 唯一的问题是我无法接收密码重置的电子邮件通知,并且在我点击“发送密码重置链接”后也没有显示任何错误 .

4 回答

  • 0

    我终于找到了问题所在 .

    当我将电子邮件列从用户表更改为“US_EMAIL”时,Illuminate \ Notifications特征中有一个函数可以检索电子邮件列 .

    Illuminate\Notifications
    
      public function routeNotificationFor($driver)
    {
    
    
        if (method_exists($this, $method = 'routeNotificationFor'.Str::studly($driver))) {
            return $this->{$method}();
        }
    
    
        switch ($driver) {
            case 'database':
                return $this->notifications();
            case 'mail':
                return $this->email;
            case 'nexmo':
                return $this->phone_number;
        }
    }
    

    解:

    on the "routeNotificationFor" function i changed this line "return $this->email;"
    

    至:

    “返回此 - > US_EMAIL;”

  • 0

    请检查 .env 文件并查找 MAIL_DRIVER . 在电子邮件测试人员中创建虚拟电子邮件,例如Mailtrap.io

    它应该如下所示使用Mailtrap.io

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=usernamefrommailtrap
    MAIL_PASSWORD=somepasswordfrommailtrap
    MAIL_ENCRYPTION=null
    

    现在测试它,如果收到电子邮件,请在Mailtrap中检查您的虚拟电子邮件 .

  • 3

    有3件事需要检查

    第一个: .env 文件

    MAIL_DRIVER=smtp 
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=587
    MAIL_USERNAME=email@email.com
    MAIL_PASSWORD=password
    MAIL_ENCRYPTION=tls
    

    这是用于 生产环境 和gmail消息

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=usernamefrommailtrap
    MAIL_PASSWORD=somepasswordfrommailtrap
    MAIL_ENCRYPTION=null
    

    这是用于测试和mailtrap消息

    第二名: config/mail.php

    确保使用正确的数据正确设置配置文件 . 或者确保从 .env 文件中调用正确的信息

    第三:刷新

    编辑 .env 文件后,不要忘记停止 php artisan serve 并再次运行它 .
    编辑 config/mail.php 文件后,不要忘记运行 php artisan config:cache 删除已保存的缓存并创建一个新缓存

  • 0

    听起来像你应该检查你的config / mail.php和.env以验证你的电子邮件设置 . 我最初的猜测是你将它设置为“mail”或“sendmail”,并且没有安装在你的机器或服务器上 .

    也许用外部电子邮件服务(mailgun,sparkpost等)创建一个免费帐户并设置它来排除它?


    编辑:再次阅读后,我认为你的问题是这样的:

    public function getEmailForPasswordReset() { return $this->EMAIL; }

    根据您的问题的顶部,您的数据库中的“电子邮件”字段实际上是“US_EMAIL” .

    public function getEmailForPasswordReset() { return $this->US_EMAIL; }

相关问题