I always have lots of problems with Mail::queue and this time the subject is not being applied properly.
This is my class:
<?php
namespace AppMail;
use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;
class PlanExpiringOrExpired extends Mailable
{
use Queueable, SerializesModels;
private $payment = null;
public function __construct($payment)
{
$this->payment = $payment;
$this->subject($this->payment->subject);
Log::debug("Subject: {$this->payment->subject}");
}
public function build()
{
$this->to($this->payment->email, $this->payment->name)
->view('mails/payment')
->with('payment', $this->payment);
return $this;
}
}
And I call it this way:
$payment = AppModelsPayments::findOrFail($id);
$payment->subject = 'Your account has been canceled';
Mail::queue(new AppMailPlanExpiringOrExpired($payment));
The log
saved correctly the following content:
[2023-02-12 11:00:04] local.DEBUG: Subject: Your account has been canceled
Yet the user received as subject: Plan Expiring or Expired
(which is basically the class name).
Since I’ve done this change recently, do you think this might be a cache-related problem? If so, I’m using Supervisor to run queues, how do I clear the cache (through PHP) without messing up the production server?
I have used in the past something like this.
Artisan::call('cache:clear');
But I’m not sure if this is correct, or if it has any implications for my production server.
3
Answers
Solved.
It was indeed a cache problem, it is also necessary to restart the queue. My solution was to create a private endpoint like
/superadmin/clear-cache
and use it whenever I need.Have you tried it this way to setup the proper subject?
Move the
subject
set intobuild
iam doing like this in queue class, EmailContactForm is a mailable class.