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