I am implementing email verification using queues in 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. 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
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?
I can see you are calling it
dispatch(new SendVerificationEmail($user));
Try calling as event(new 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;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.