Laravel邮件未从Cron Job发送

时间:2019-05-10 00:57:02

标签: laravel email cron

我正在从我的应用程序发送邮件,从用户请求发送邮件没有问题。

但是从Cron Job邮件没有发送出去。

我正在监听MessageSentMessageSending事件并记录它们。有趣的是,从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中的错误?

1 个答案:

答案 0 :(得分:1)

将$ _SERVER ['SERVER_NAME']设置为您的域。