2

I've been trying to get fortify's native email verification feature to use mailjet so templates can easily be adjusted. I've hit a bit of a roadblock as all tutorials and sources I've found are all about blade templates. Does someone have some pointers in the right direction or perhaps personal experience setting this up?

Thanks in advance!

Antharan
  • 21
  • 1

1 Answers1

-1

You need to bind your own implementation of Laravel\Fortify\Contracts\VerifyEmailViewResponse in the FortifyServiceProvider class.

# app/Providers/FortifyServiceProvider.php

namespace App\Providers;

use App\Actions\Fortify\YourClassHere;
use Laravel\Fortify\Contracts\VerifyEmailViewResponse;

class FortifyServiceProvider extends ServiceProvider
{
    public function boot()
    {
        app()->singleton(VerifyEmailViewResponse::class, YourClassHere::class);
    }
}
# app/Actions/Fortify/YourClassHere.php

namespace App\Actions\Fortify;

use Laravel\Fortify\Contracts\VerifyEmailViewResponse;

class YourClassHere extends VerifyEmailResponse
{
    public function toResponse($request)
    {
        // your logic here.
        // since mailjet uses an api, perhaps return the response of a curl call,
        // or a response form Http::get(...)
        // or use a third-party package like laravel-mailjet (https://mailjet.github.io/laravel-mailjet/)
    }
}

The logic that sends the verification email is part of the Illuminate\Auth\MustVerifyEmail trait. If you want to change it, you need to override it in your User model.

class User extends Authenticatable
{
    /**
     * Send the email verification notification.
     *
     * @return void
     */
    public function sendEmailVerificationNotification()
    {
        // your logic here.
    }
}
IGP
  • 14,160
  • 4
  • 26
  • 43
  • I've done this but it still seems to send the standard laravel mail instead of going through the specified logic in the toResponse function. – Antharan Feb 07 '22 at 19:05
  • Disregard everything I posted then, what you want to do is override a method in your User model. – IGP Feb 07 '22 at 19:56