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

rajulmondal5's avatar

Laravel mail notifications not working

Guys need help in laravel notifications, is there any1 help me out with this while doing registration I need to have a mail notification

protected function create(array $data) { $user = User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), ]);

$user->notify(new UserRegistered());

return $user;

}

here is the notification class

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use NotificationChannels\HipChat\HipChatChannel; use NotificationChannels\HipChat\HipChatMessage;

class UserRegistered extends Notification { use Queueable;

/**
 * Create a new notification instance.
 *
 * @return void
 */
public function __construct()
{
    
}

/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return ['mail'];
}

/**
 * Get the mail representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\MailMessage
 */
public function toMail($notifiable)
{
    return (new MailMessage)
                ->line('The introduction to the notification.')
                ->action('Notification Action', url('/'))
                ->line('Thank you for using our application!');
}

/**
 * Get the array representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function toArray($notifiable)
{
    return [
        
    ];
}

}

0 likes
1 reply
Mahesvaran's avatar

Did you configure MAIL_DRIVER settings in .env file ? you can create free account in mailtrap.io or you just set log as your MAIL_DRIVER and then mail message will be written in your application log file.

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=<your-mail-trap-username>
MAIL_PASSWORD=<your-mail-trap-password>
MAIL_ENCRYPTION=null

or

MAIL_DRIVER=log

Please or to participate in this conversation.