Laravel将激活链接发送到特定电子邮件



我希望注册后的激活链接发送到一封电子邮件,这是因为我不希望每个人都创建管理员帐户,因此任何人都可以创建管理员帐户,应用程序的所有者将通过单击其电子邮件上的激活链接(所有者电子邮件(来激活他的帐户。

protected function postAdminRegistration(Request $request)
{
$validatedData = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
try {
$validatedData['password'] = bcrypt(array_get($validatedData, 'password'));
$validatedData['activation_code'] = str_random(30).time();
$user = app(User::class)->create($validatedData);
} catch (Exception $exception) {
logger()->error($exception);
return redirect()->back()->with('message', 'Unable to create new user.');
}
$user->notify(new UserRegisteredSuccessfully($user));
return redirect()->route("user.loginform")->withSuccess('Successfully created a new account.
Please check your email and activate your account.');
}

用户注册成功

public function toMail($notifiable)
{
$user = $this->user;
return (new MailMessage)
->from('****@gmail.com')
->subject('Successfully created new account')
->greeting(sprintf('Hello %s', $user->fname))
->line('You have successfully registered to our system. Please activate your account.')
->action('Click Here',
route('user.activate', $user->activation_code))->line('Thank you for using our application!');
}

class User extends Authenticatable
{
use Notifiable;
protected $fillable = [
'name','email','password'
];
protected static $logFillable = true;
protected $hidden = [
'password', 'remember_token',
];
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPassword($token.'/'.$this->email));
}
}

添加到代码中的方法

return (new MailMessage)
->from('****@gmail.com')
->to("xyz@email.com")
...

有关更多详细信息 https://laravel.com/docs/6.x/notifications

无法添加评论,所以我以这种方式发布可能的答案; 我假设您可以通过以下方式添加收件人->to('someone@somewhere.not')

最新更新