Ace Ace - 1 month ago 16
PHP Question

Laravel 5 Sending email to owner after a user register

Im using the default login and registration system of laravel. I just want to do whenever a new user were successfully registered an email will be sent to one of the email address that i will input, like sending an email to me to notify me that a new user register.

How will I do this?

Answer

You can simply overwrite register method in AuthController.

Put something like this and it will send super simple email to registered user:

public function register(Request $request)
{
    // original script, do not touch it
    $validator = $this->validator($request->all());

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

    \Auth::guard($this->getGuard())->login($this->create($request->all()));

    // Your custom script
    \Mail::raw('Welcome ' . $request->input('name') . '!', function ($m) use ($request) {
        $m->to($request->input('email'))->subject('Registration successful!');
    });

    return redirect($this->redirectPath());
}

To learn more about mailing, You should read official docs: https://laravel.com/docs/5.2/mail