在Laravel-5.8应用程序中,我创建了一个用于用户注册的终结点。成功注册后,身份验证邮件将发送给用户。我正在使用邮件陷阱来做到这一点。
AuthController
public function signup(Request $request)
{
$request->validate([
'name' => 'required|string|min:2',
'email' => 'required|string|email|unique:users',
'password' => 'required|string|confirmed|min:6'
]);
$user = new User([
'name' => $request->name,
'email' => $request->email,
'password' => bcrypt($request->password),
'activation_token' => str_random(60)
]);
$user->save();
$avatar = Avatar::create(strtoupper($user->name))->getImageObject()->encode('png');
Storage::put('avatars/'.$user->id.'/avatar.png', (string) $avatar);
$user->notify(new SignupActivate($user));
return response()->json([
'message' => 'Successfully created user!'
], 201);
}
public function signupActivate($token)
{
$user = User::where('activation_token', $token)->first();
if (!$user) {
return response()->json([
'message' => 'This activation token is invalid.'
], 404);
}
$user->active = true;
$user->activation_token = '';
$user->email_verified_at = Carbon::now()->toDateTimeString();
$user->save();
return $user;
}
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=**********
MAIL_PASSWORD=**********
MAIL_ENCRYPTION=tls
mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME', '**********'),
'password' => env('MAIL_PASSWORD', '**********'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'log_channel' => env('MAIL_LOG_CHANNEL'),
];
当我通过Postman将其发布到数据库时,它假定要发送电子邮件。它已发布到数据库中,但没有发送邮件。我收到此错误: