Creating registration emails upon registration

Jun 23, 2017 email laravel error registration

protected function create(array $data)
//create confirmation code
$confirmation_code = str_random(30);

//main bulk of user creation
$user = User::create([
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'confirmation_code' => $confirmation_code,

//link to a role
$role_client = Role::where('name', 'client')->first();

//send mail upon user creation
Mail::to($user)->send(new RegistrationEmail($user));

return $user;

function can be found in Auth/RegisterController.php

Make sure to customise the fillable if you’ve modified the table, or you may get an error similar to “General error: 1364 Field 'confirmation_code' doesn't have a default value”. This means you are passing an empty value to the table.

It’s preferable you don’t remove the STRICT mode. As good practice you should always have it on and be aware of what you are passing the correct type to the database.

For testing purposes we’ll use mailtrap; change the mail environment variables in the .env file to your credentials.

If you found the following info helpful, I'm happy to accept any donations of the following cryptocurrencies.

  • Bitcoin - 17DTiPExzP9StqveW428acEyB4mVMfKbiK
  • Ethereum - 0x87B8307FD20dc90cc05c94905Ec593134D32B6FF
  • Litecoin - LZMiz5U5sVq9doMLYE3gfLJrxCQDKuyCmU
  • Neo - AXv71WB38ajc1KUUEnxQKhynLLPc4BapVb