I have notifications that implement ShouldBroadcast and ShouldQueue (I'm using Redis
and laravel-echo-server
to broadcast notifications). I have to send mail too. So I have toMail
method to send the user an email. But the problem is that the email is not sending!
I double-checked everything! My mail server configuration is correct (I tested it with another way of sending email), my notification is working well and as I know, everything is OK! but the email is not sending!
For a better explanation, I'll send the code here!
In my TicketController
, I have an instance of Ticket
model (that uses Notifiable
), so I'm using this line of code to send the notification:
$ticket->notify(new AdminTicketCreated());
and in my notification class:
class AdminTicketCreated extends Notification implements ShouldBroadcast, ShouldQueue
{
use Queueable, SerializesModels;
public function via($notifiable): array
{
return [SmsChannel::class, 'mail', 'broadcast', UserDatabaseChannel::class];
}
public function toMail($notifiable): MailMessage
{
$user = $notifiable->user;
return (new MailMessage)
->subject('ارسال تیکت توسط ادمین')
->replyTo($user->email, $user->name)
->view('emails.ticket_send_admin', ['user' => $user, 'ticket' => $notifiable]);
}
.
.
.
.
.
}
One of the problems I have is that I don't know how to debug it! Just before return (new MailMessage)...
I Logged $notifiable
and $user
and their values are correct. But in the view
, I'm using Log
to check if it's rendering or not, and unfortunately, it's not working!
I'll be appreciated any response. Thank you :)
Update: My job is running with php artisan queue:listen
. So, when I change my code I don't need to rerun it. Also, my laravel-echo-server
is running too.
- I created a
Mailable
class instead ofMailMessage
and now it's working and sending the emails! But I don't know why! TheMailMessage
way was working till two days ago and now it's not working anymore? :|