0

I am trying to send an email to a new registered user but for some reason the email is not being sent. I have the following:

app/Http/Controllers/Auth/RegisterController.php

protected function create(array $data)
{   
    $user = User::create([
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]); 
    Mail::to($data['email'])->send(new WelcomeMail($user));

    return $user;
}   

app/Mail/WelcomeMail.php

class WelcomeMail extends Mailable
{
    use Queueable, SerializesModels;

    public $user;

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

    /** 
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {   
        return $this->view('emails.welcome');
    }   
}

app/Http/Controllers/Auth/WelcomeController.php

class WelcomeController extends Controller
{
    /** 
     * Send Verification Email
     *
     * @param  Request  $request
     * @return Response
     */
    public function sendEmail(Request $request)
    {   
        Mail::to($request->user())->send(new WelcomeMail($user));
    }   
}

And my blade is at resources/views/emails/welcome.blade.php.

I think I might be missing a route to activate the WelcomeMail controller?

I know the blade is fine because it works whenever I try to route it manually

Route::get('/mailable', function (Request $request) {
    $user = $request->user();

    return new App\Mail\WelcomeMail($user);
});

Any idea what might be the issue?

EDIT

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=9d1204***
MAIL_PASSWORD=7919be***
MAIL_ENCRYPTION=null
A.J
  • 1,140
  • 5
  • 23
  • 58

1 Answers1

1

Try changing the QUEUE_DRIVER value to sync in your .env and see if anything happens.

plmrlnsnts
  • 1,644
  • 12
  • 10
  • Doesn't seem to change the outcome. The new controller still doesn't run. Not sure if it is supposed to though, because I have the `Mail::to` in the `RegisterController`.. – A.J Dec 14 '17 at 17:19