[英]EmailVerification using queue in laravel
I am implementing email verification using queues in laravel. 我正在使用Laravel中的队列来实现电子邮件验证。 I followed a documentation on how to achieve this religiously but then, i don't receive the email verification in my mailtrap inbox and neither do i get any error as well.
我遵循了有关如何认真实现此目标的文档,但是随后,我在邮件陷阱收件箱中未收到电子邮件验证,也没有收到任何错误消息。 Below is how i configured my mail sending .
以下是我配置邮件发送的方式。 Why is the email not being sent to my mailtrap.
为什么电子邮件没有发送到我的邮件陷阱。 I am newbie with laravel.
我是laravel的新手。 Thanks for your help
谢谢你的帮助
env 环保
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=
vendor/laravel/framework/src/Foundation/Auth/RegistersUsers 供应商/ 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]);
}
}
EmailVerification 电子邮件验证
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,
]);
}
}
SendVerificationEmail 发送验证电子邮件
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);
}
}
Console 安慰
[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
Do you have SendVerificationEmail event? 您有SendVerificationEmail事件吗?
I can see you are calling it 我可以看到你在打电话
dispatch(new SendVerificationEmail($user)); dispatch(新的SendVerificationEmail($ user));
Try calling as event(new SendVerificationEmail($user)) 尝试作为事件调用(新的SendVerificationEmail($ user))
Also if event is missing add this on your events folder. 另外,如果缺少事件,请将其添加到您的事件文件夹中。
<?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.