這是有效的代碼:
Mail::to($emails)->send(new ExceptionOccurred($e));
然后我把它改成:
Mail::to($emails)->queue(new ExceptionOccurred($e));
當我這樣做時,我收到錯誤:
ErrorException: Undefined property: App\Mail\ExceptionOccurred::$content in C:\inetpub\wwwroot\laravel\app\Mail\ExceptionOccurred.php:33
這是 ExceptionOccurred.php:
namespace App\Mail;
use Illuminate\Bus\Queueable;
// use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class ExceptionOccurred extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($content)
{
$this->content = $content;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('mail.ExceptionOccurred')
->subject('Exception on live instance')
->with('content', $this->content);
}
}
這是例外處理程式的相關部分:
if ( $exception instanceof Exception ) {
$e = FlattenException::create($exception);
} else {
$e = $exception;
}
$emails = json_decode( env('MAINTAINER_EMAILS') );
if (app()->environment('production') || app()->environment('testing') ) {
Mail::to($emails)->send(new ExceptionOccurred($e));
}
再次重復,Mail::send() 有效,但 Mail::queue() 無效。我相信佇列設定正確。
uj5u.com熱心網友回復:
您必須在構造之前定義內容屬性,如下所示:
namespace App\Mail;
use Illuminate\Bus\Queueable;
// use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class ExceptionOccurred extends Mailable
{
use Queueable, SerializesModels;
public $content;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($content)
{
$this->content = $content;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('mail.ExceptionOccurred')
->subject('Exception on live instance')
->with('content', $this->content);
}
}
參考:https : //laravel.com/docs/8.x/mail#view-data
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/399650.html
標籤:拉拉维尔 laravel-8 laravel 队列 laravel 邮箱
下一篇:Python-在回傳陳述句上縮進