亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

應用程序無法使用 Mail::...queue() 發送電子郵件

應用程序無法使用 Mail::...queue() 發送電子郵件

PHP
qq_遁去的一_1 2023-09-15 21:21:47
我在使用時遇到郵件問題queue。如果我使用 Mail send(),一切正常。控制器:Mail::to($order_data->client_email)    ->cc([        ['email' => $order_data->seller->email],        ['email' => auth()->user()->email]    ])    ->queue(new SendOrderConfirmation($order_data));可郵寄的:class SendOrderConfirmation extends Mailable{    use Queueable, SerializesModels;    /**     * Defines a public variable $order_data that we will be using to pass in parameters from our controller.     */    public $order_data;    /**     * Create a new message instance.     */    public function __construct($data)    {        // set email data        $this->order_data = $data;        // Set Reply to address        // Basically, the name and email from who's sending this email        $this->replyto(auth()->user()->email, auth()->user()->name);        // Set from        $this->from(auth()->user()->email, auth()->user()->name);        // set email subject        $this->subject('Laminar - Confirma??o da Encomenda N.o '.$this->order_data->order_nr);    }    /**     * Build the message.     *     * @return $this     */    public function build()    {        return $this->view('send_emails.Lamimail.SendOrderConfirmation');    }}如果我使用隊列()觸發電子郵件,我會收到有關望遠鏡作業的錯誤消息:Trying to get property 'name' of non-object (View: path\resources\views\send_emails\Lamimail\SendOrderConfirmation.blade.php)但是,在郵件視圖中,名稱是一個簡單的auth()->user()->name.有誰知道我在隊列中失蹤了?
查看完整描述

2 回答

?
慕森卡

TA貢獻1806條經驗 獲得超8個贊

當作業或電子郵件為 時queued,您將無法再訪問會話(會話中的變量),因為“異步”處理作業時沒有 HTTP 訪問。因此,您無法獲得經過身份驗證的用戶(處理作業時沒有特定用戶)。

您需要將經過身份驗證的用戶(作為對象或數組)發送到類的構造函數SendOrderConfirmation,然后您可以在類內部使用。

非隊列將起作用,因為它將是sync并且仍然可以使用會話。


查看完整回答
反對 回復 2023-09-15
?
藍山帝景

TA貢獻1843條經驗 獲得超7個贊

您是否嘗試過僅將名稱作為數據發送,將其添加到您的名稱$order_data并將其顯示在郵件刀片中,看看是否可以解決問題。



查看完整回答
反對 回復 2023-09-15
  • 2 回答
  • 0 關注
  • 151 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號