Laravel 5.7-未发送验证电子邮件

Mar*_*kus 4 email email-validation laravel laravel-5 laravel-5.7

我已经将laravel实例从5.6版升级到5.7版。现在,我尝试使用laravel中内置电子邮件验证

我的问题是,当我使用“重新发送”功能到达电子邮件时,成功注册后没有收到电子邮件。

问题是什么?

JMo*_*ura 16

我有这个完全相同的问题。那是Laravel的默认代码。

为了在成功注册后发送电子邮件,您可以执行以下解决方法:

App\Http\Controllers\Auth\RegisterController

改变这个:

protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }
Run Code Online (Sandbox Code Playgroud)

对此:

protected function create(array $data)
    {
        $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);

        $user->sendEmailVerificationNotification();

        return $user;
    }
Run Code Online (Sandbox Code Playgroud)


laz*_*aze 9

我也遇到过同样的问题。当我检查源代码时,不必实现调用sendEmailVerificationNotfication()方法,您只应将事件处理程序添加到EventServiceProvider.php,因为由于您先前创建了事件处理程序,因此Larael无法对其进行更新。它看起来应该像这样:

namespace App\Providers;

use Illuminate\Support\Facades\Event;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],
    ];
Run Code Online (Sandbox Code Playgroud)

  • 遵循 Laravel 结构,这应该是正确的答案,非常感谢。 (3认同)

Zan*_*ane 8

如果您有自定义注册页面,则可以在创建用户后触发该事件,如下所示:

event(new Registered($user));


小智 5

如果其他人正在寻找同一问题的解决方案。

请阅读文档,它准确地解释了解决此问题需要做什么

https://laravel.com/docs/5.7/verification

简而言之,如果您已经在使用 5.7(即您的users表中有必要的字段),您需要做的就是以下操作:

  • 让您的User模型实现该MustVerifyEmail接口。
  • 添加['verify' => true]Auth::routes方法中Auth::routes(['verify' => true]);

您可以在上面的链接中找到有关电子邮件验证的所有信息。