簡體   English   中英

在Laravel中使用隊列進行電子郵件驗證

[英]EmailVerification using queue in laravel

我正在使用Laravel中的隊列來實現電子郵件驗證。 我遵循了有關如何認真實現此目標的文檔,但是隨后,我在郵件陷阱收件箱中未收到電子郵件驗證,也沒有收到任何錯誤消息。 以下是我配置郵件發送的方式。 為什么電子郵件沒有發送到我的郵件陷阱。 我是laravel的新手。 謝謝你的幫助

環保

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=

供應商/ laravel / framework / src / Foundation / Auth / RegistersUsers

public function register(Request $request)
{
    $this->validator($request->all())->validate();

    event(new Registered($user = $this->create($request->all())));

    dispatch(new SendVerificationEmail($user));
    return view('verification');

    // $this->guard()->login($user);

    // return $this->registered($request, $user)
    //                 ?: redirect($this->redirectPath());
}

public function verify($token)

{
    $user = User::where('email_token',$token)->first();
    $user->verified = 1;
    if($user->save())
    {

        return view('emailconfirm',['user'=>$user]);

    }
}

電子郵件驗證

class EmailVerification extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */

     protected $user;
    public function __construct($user)
    {
        //
        $this->user = $user;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
            return $this->view('email.email')->with([
            'email_token'=> $this->user->email_token,
        ]);
    }
}

發送驗證電子郵件

class SendVerificationEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */

    protected $user;
    public function __construct($user)
    {
        //
        $this->user = $user;

    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
        $email = new EmailVerification($this->user);
        Mail::to($this->user->email)->send($email);
    }
}

安慰

[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail
[2017-10-06 12:05:52] Processing: App\Jobs\SendVerificationEmail

您有SendVerificationEmail事件嗎?

我可以看到你在打電話

dispatch(新的SendVerificationEmail($ user));

嘗試作為事件調用(新的SendVerificationEmail($ user))

另外,如果缺少事件,請將其添加到您的事件文件夾中。

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use App\User;

class SendVerificationEmail
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $user;

    /**
     * Create a new event instance.
     *
     * @param User $user
     * @return void
     */
    public function __construct(User $user)
    {
        $this->user = $user;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM