Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Amalmax's avatar

how to send an email to admin after verify the user?

I am working with Laravel 5.7 and developing a simple booking system. in my application is running following logic.

  1. user can book a taxi using booking form 2.user should be logged with email and click the verification link. 3.then after click user verification link an email should send to the admin with user data.

following as user booking and sending to user verification controller,

<?php

namespace App\Http\Controllers;
use App\Mail\VerifyMail;
use App\User;
use App\VerifyUser;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class UserController extends Controller
{
        protected function store(Request $request)
    {

        $user = new User;

        $user->email = $request->input('email');
        $user->name = $request->input('name');
        $user->address = $request->input('address');
        
        $user->save();

        $verifyUser = VerifyUser::create([
            'user_id' => $user->id,
            'token' => str_random(40)
        ]);

        Mail::to($user->email)->send(new VerifyMail($user));

       return redirect()->back()->with('info','We sent you an activation code. Check your email and click on the link to verify');
    }

    public function verifyUser($token)
    {
        $verifyUser = VerifyUser::where('token', $token)->first();
        if(isset($verifyUser) ){
            $user = $verifyUser->user;
            if(!$user->verified) {
                $verifyUser->user->verified = 1;
                $verifyUser->user->save();
               
                $info = "Your e-mail is verified. You can now login.";
            }else{
                $info = "Your e-mail is already verified. You can now login.";
            }
        }else{
             return redirect()->back()->with('warning', "Sorry your email cannot be identified.");
        }

         return redirect()->back()->with('info', $info);
    }
}

and email verification link view file

<!DOCTYPE html>
<html>
<head>
    <title>Welcome Email</title>
</head>

<body>
<h2>Welcome to the site {{$user['name']}}</h2>
<br/>
Your registered email-id is {{$user['email']}} , Please click on the below link to verify your email account
<br/>
<a href="{{url('user/verify', $user->verifyUser->token)}}">Verify Email</a>
</body>

</html>

but I have not an idea about step 3 to send an admin after verify user verification link. my admin email is like this [email protected] how could I manage this problem?

0 likes
9 replies
Amalmax's avatar

No, any simple way without event fire.

JohnBraun's avatar

@AMALMAX - Hey wouldn’t you want to fire an event?

I see you mentioning a booking, but I only see a user registration and verification form. Where is the booking handled? Do you want to send that information to the admin too?

If you only want to send the newly verified user’s data to your admin, then the following would suffice:

  1. In your verifyUser() method, after the user is verified add:
public function verifyUser($token)
{
  // ....

  $info = “Successfully verified, ..... “
  Mail::to(‘[email protected]’)->send(new UserWasVerifiedMail($verifyUser->user));

  // ...
}

Then you will need to generate the UserWasVerifiedMail mailable, using

php artisan make:mail UserWasVerifiedMail

To read more about mailing, see the Laravel documentation: https://laravel.com/docs/5.8/mail#generating-mailables

Amalmax's avatar

@johnbraun yes, you got My need. then I would like to know what shall I do using UserWasVerifiedMail in artisan command?

JohnBraun's avatar
Level 33

@AMALMAX - Running the artisan command will generate a new class in your app/Mail directory using the name you've provided. This is what they call a 'Mailable'.

In this UserWasVerifiedMail mailable, you accept the user in the constructor and use it in the build method to render a Mail using a view (which you also need to generate).

example of a UserWasVerifiedMail mailable:

// make sure you add the property as public, otherwise it will not be available in the view
public $user;

public function __construct(User $user)
{
  $this->user = $user;
}

public function build()
{
  return $this->subject('New user was verified')->view('mails.user.verified');
}

** After you've created this mailable, make sure to import it in your UserController. **

Now, create a new file in resources/views/mails/user called 'verified.blade.php'.

In this file, you can write up your e-mail in HTML and use the blade helpers and syntax as usual. Since you've made the $user property public, it is accessible in here.


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>New user was verified</title>
</head>
<body>
  Dear admin, <br> <br>
  A new user was verified in your system: <br> <br>
  Name of the user: {{ $user->name }} <br> 
  <!-- etc, etc... -->
</body>
</html>

Does this answer your question?

1 like
Amalmax's avatar

@johnbraun Okey, clear but one thing is this way to import mailable to controller use Illuminate\Support\Facades\Mail;? Thanks.

JohnBraun's avatar

@AMALMAX - Yes, indeed you'll need to import the Illuminate\Support\Facades\Mail facade class in your UserController.

JohnBraun's avatar

You need to import your mailable in your UserController, in your case:

use App\Mail\UserWasVerifiedMail;

Please or to participate in this conversation.