It seems like the issue is with the url method in the VerifyEmail notification class. By default, it uses the url method from the Illuminate\Routing\UrlGenerator class, which generates URLs based on the current request. Since the request is coming from the server, it's using the server's hostname instead of the FRONTEND_URL.
To fix this, you can override the url method in the VerifyEmail notification class to use the FRONTEND_URL instead of the current request. Here's an example:
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class VerifyEmail extends Notification
{
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
$verificationUrl = $this->verificationUrl($notifiable);
return (new MailMessage)
->subject('Verify Email Address')
->line('Please click the button below to verify your email address.')
->action('Verify Email Address', $verificationUrl)
->line('If you did not create an account, no further action is required.');
}
protected function verificationUrl($notifiable)
{
return str_replace(
'{{id}}',
$notifiable->getKey(),
str_replace(
'{{hash}}',
$notifiable->getEmailForVerification(),
config('app.frontend_url') . '/email/verify/{{id}}/{{hash}}'
)
);
}
public function url($route, $parameters = [], $absolute = true)
{
return config('app.frontend_url') . '/' . ltrim($route, '/');
}
}
In this example, we're overriding the url method to always return the FRONTEND_URL instead of the current request. We're also using the config helper function to get the FRONTEND_URL from the .env file.
Make sure to update the config/app.php file to include the FRONTEND_URL:
'frontend_url' => env('FRONTEND_URL', 'http://localhost:3000'),
And update the .env file to include the FRONTEND_URL:
FRONTEND_URL=http://localhost:3000
With these changes, the verification URL should now use the FRONTEND_URL instead of the server's hostname.