未应用Laravel邮件队列主题

lo8azlld  于 2023-02-14  发布在  其他
关注(0)|答案(2)|浏览(123)

我总是有很多问题的邮件::队列和这一次的主题是没有得到适当的应用。
这是我的课

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

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;
    }
}

我是这么称呼它的:

$payment = \App\Models\Payments::findOrFail($id);
$payment->subject = 'Your account has been canceled';

\Mail::queue(new \App\Mail\PlanExpiringOrExpired($payment));

log正确保存了以下内容:

[2023-02-12 11:00:04] local.DEBUG: Subject: Your account has been canceled

然而,用户收到的主题是:Plan Expiring or Expired(基本上就是类名)。
因为我最近做了这个修改,你认为这可能是缓存相关的问题吗?如果是,我使用Supervisor来运行队列,我如何清除该高速缓存(通过PHP)而不扰乱生产服务器?
我过去曾使用过类似的方法:

\Artisan::call('cache:clear');

但我不确定这是否正确,或者它是否对我的生产服务器有任何影响。

ev7lccsx

ev7lccsx1#

你试过用这种方法来设定合适的主题吗?

private $payment = null;

public function __construct($payment)
{
    $this->payment = $payment;
}

public function build()
{
    $this->to($this->payment->email, $this->payment->name)
        ->subject($this->payment->subject)
        ->view('mails/payment')
        ->with('payment', $this->payment);

    \Log::debug("Subject: {$this->payment->subject}");

    return $this;
}

subject集合移到build

zbdgwd5y

zbdgwd5y2#

我在队列类中这样做,EmailContactForm是一个可邮寄类。

public function handle()
{
    $email = new EmailContactForm([
        'locale' => $this->data['locale'],
        'from_email' => $this->data['from_email'],
        'name' => $this->data['name'],
        'topic' => $this->data['topic'],
        'subject' => $this->data['subject'],
        'msg' => $this->data['msg']
    ]);

    Mail::to($this->data['to_email'])
        ->bcc(config('app.mail_from_address'))
        ->send($email);
}

相关问题