我使用 Laravel 5.8,注册后想发两封邮件。我希望第一封电子邮件在注册后直接发送给客人,第二封电子邮件在客人确认他的电子邮件地址后发送给用户。下面,这可以在下面的功能验证中看到。
保存方法
public function save(Request $request)
{
$validate = array(
'name' => ['required', 'string', 'min:2', 'max:255'],
'surname' => ['required', 'string', 'min:2', 'max:255'],
'phone' => ['required', 'string', 'min:6', 'max:20'],
'land' => ['required', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:guests'],
'user_id' => ['required', 'string', 'exists:users,id']
);
$this->validate($request, $validate);
$token = $request['user_id'].Str::random(22);
$guest = new Guest;
$guest->name = $request['name'];
$guest->surname = $request['surname'];
$guest->phone = $request['phone'];
$guest->land = $request['land'];
$guest->email = $request['email'];
$guest->user_id = $request['user_id'];
$guest->email_token = $token;
$guest->save();
MailController::send($request['email'], $request['name'], $token);
//if (email_verified === 1)
MailController::user_send($request['user_id'], $guest);
return view('guest-success');
}
验证方法
public function verify($token = false)
{
if ($token == false) $token = Cookie::get('token') ?? false;
else Cookie::queue('token', $token, 60 * 24 * 365);
if ($token === false) return view('no_tp');
$guest = Guest::where('email_token', $token)->first();
if ($guest === null) return view('no_tp');
$guest->email_verified = 1;
$guest->email_verified_at = time();
$guest->save();
$user = User::find($guest->user_id);
Cookie::queue('TP', $user->user_id, 60 * 24 * 365);
return view('public-profile', compact('user'));
}