Reputation: 4756
Trying to send an activation mail after registering on the website (using the Auth Controller).
Here's the code of my controller:
protected function create(array $data)
{
$data['activation_code'] = str_random(20);
return User::create([
'firstname' => $data['firstname'],
'lastname' => $data['lastname'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'activation_code' => $data['activation_code'],
]);
Mail::send('emails.register', $data, function($message) use ($data)
{
$message->from('[email protected]', "Foodtruckbestellen.be");
$message->subject("Welkom bij foodtruckbestellen.be");
$message->to($data['email']);
});
}
and here's the code of my email view:
<h1>Hi {{ $data['firstname'] }}</h1>
<p>
Link = <a href="http://192.168.33.10/register/activate?code={{ $data['verification_code'] }}'">CLICK ME</a>
</p>
Part of my .env:
MAIL_DRIVER=mail
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
The user get's saved in the DB without any problem, but my email isn't sending out. I don't receive any errors, so I'm not sure what's going on.
Upvotes: 0
Views: 113
Reputation: 2956
You need to setup your .env file. Just register at mailtrap and copy/paste the the username and password from mailtrap to the .env file.
Edit:
Mail::send('email.register', ['data' => $data], function ($message) use ($data) {
$message->from('[email protected]', 'Foodtruckbestellen.be');
$message->to($data['email']);
$message->subject('Welkom bij foodtruckbestellen.be);
});
Try this code. I think you must use use
and $data
must be inside array. Hope this was helpful.
Upvotes: 2