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

OttoY's avatar
Level 3

Custom EmailVerificationNotification not working in Laravel Breeze

I created a custom RegisterController to register a user via API. I want to automatically send an email notification after the user is successfully created.

public function register(Request $request) { $validator = Validator::make($request->all(), [ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:8', 'c_password' => 'required|same:password', ]);

    if ($validator->fails()) {
        return response(['errors' => $validator->errors()], 422);
    }

    $user = User::create([
        'name' => $request->name,
        'email' => $request->email,
        'password' => Hash::make($request->password),
    ]);

    $

    $token = $user->createToken('MyApp')->accessToken;

    // Send the email verification link
    $user->sendEmailVerificationNotification();

    // return response(['user' => $user, 'access_token' => $token]);
    return response("User succesfully created");
}

I use postman to register the user but I receive this strange error message after the user is created.

When I register the user manually via the browser, the email notification works and I do receive an email.

Please advise.

Thanks, Otto

0 likes
3 replies
LaryAI's avatar
Level 58

The issue you're facing is that the sendEmailVerificationNotification method is not working when registering a user via API. This is because Laravel Breeze uses the MustVerifyEmail trait, which expects the user to be registered through the built-in registration routes.

To solve this problem, you need to manually send the email verification notification after creating the user. Here's how you can modify your code to achieve this:

use Illuminate\Auth\Events\Registered;
use Illuminate\Support\Facades\Validator;

public function register(Request $request)
{
    $validator = Validator::make($request->all(), [
        'name' => 'required|string|max:255',
        'email' => 'required|string|email|max:255|unique:users',
        'password' => 'required|string|min:8',
        'c_password' => 'required|same:password',
    ]);

    if ($validator->fails()) {
        return response(['errors' => $validator->errors()], 422);
    }

    $user = User::create([
        'name' => $request->name,
        'email' => $request->email,
        'password' => Hash::make($request->password),
    ]);

    event(new Registered($user)); // Manually trigger the Registered event

    $token = $user->createToken('MyApp')->accessToken;

    return response("User successfully created");
}

By manually triggering the Registered event, you ensure that the email verification notification is sent even when registering a user via API.

Make sure to import the Registered event at the top of your file:

use Illuminate\Auth\Events\Registered;

This should resolve the issue and send the email verification notification when registering a user via API.

OttoY's avatar
Level 3

This is the error message I receive.

Symfony\Component\Mailer\Exception\TransportException: Connection could not be established with host "ssl://smtp.hostinger.com:465": stream_socket_client(): SSL operation failed with code 5. OpenSSL Error messages: error:80000002:system library::No such file or directory

OttoY's avatar
Level 3

I followed your solution but I still receive the same error.

Symfony\Component\Mailer\Exception\TransportException: Connection could not be established with host "ssl://smtp.hostinger.com:465": stream_socket_client(): SSL operation failed with code 5. OpenSSL Error messages: error:80000002:system library::No such file or directory

Please or to participate in this conversation.