Я отправляю почту из моего приложения, и при отправке их по запросу пользователя проблем не возникает.
Но из Cron Job письма не отправляются.
Я слушаюMessageSent
и MessageSending
события и их регистрация.Что интересно, почта, отправленная с заданий cron, появляется в журналах.
Код задания Cron
class UserPracticeLessonsCheckJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
$time_for_payment = Carbon::now()
->subMinutes(config('payment.minutes_for_payment'));
UserPaymentCheck::where('created_at', '<', $time_for_payment)
->with('user')->get()
->each(function ($userPaymentCheck) use ($time_for_payment) {
$user = $userPaymentCheck->user;
if ($user->hasUnpaidPracticeLessons()) {
$user->removeUnpaidPracticeLessons();
// Send mails to user with cancelled lessons
$user->sendPracticeLessonsCancellationMail();
}
$userPaymentCheck->delete();
});
}
}
Черта пользователя с функцией sendPracticeLessonsCancellationMail
:
trait SendPracticeLessonsCancellationMail
{
public function sendPracticeLessonsCancellationMail()
{
\Mail::to($this)->send(new PracticeLessonsCancellationMail($this));
}
}
И класс Mailable:
class PracticeLessonsCancellationMail extends Mailable
{
use Queueable, SerializesModels;
private $user;
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this
->markdown('emails.practice.practice-schedule-cancellation')
->subject(app_name() . ': ' . __('students.backend.emails.practice.practice_schedule_cancellation'))
->attachData($this->user->practice_schedule_pdf->stream(), $this->user->full_name . ' - planificare.pdf', [
'mime' => 'application/pdf',
]);
}
}
Это проблема конфигурации или ошибка в Laravel?