我在发送带有附件的电子邮件时遇到问题。问题是当我将发送电子邮件放入作业并运行它时,它显示如下错误:
不允许序列化“闭包”
任何解决方案?
我的工作文件“SendEmailCovernote.php”
public $email, $data, $pdf, $doc_numb_covernote, covernote_created_at;
public function __construct($email, $data, $pdf, $doc_numb_covernote, $covernote_created_at)
{
$this->email = $email;
$this->data = $data;
$this->pdf = $pdf;
$this->doc_numb_covernote = $doc_numb_covernote;
$this->covernote_created_at = $covernote_created_at;
}
public function handle()
{
Mail::send('email.covernote_content', ['Body' => $data], function($message) use ($email, $pdf, $doc_numb_covernote, $covernote_created_at)
{
$message->from('support@jcr.com');
$message->subject('Pengiriman Covernote');
$message->attachData($pdf, $doc_numb_covernote.'_facultative_covernote_'.Str::slug($covernote_created_at, '_').'.pdf');
$message->to($email);
});
}
我的控制器
use App\Jobs\SendEmailCovernote;
use PDF;
public function store(Request $request)
{
//Some Other Code
$data['covernote'] = CoverNote::where('id', $covernote->id)->first();
$rsc_id = $data['covernote']->closing_instruction->confirmation_sent->id;
$data['total_rate_agreed'] = 'Some Other Data';
$pdf = PDF::loadView('risk_covering.covernote.print4', $data)->setPaper('a4', 'portrait');
$doc_numb_covernote = $data['covernote']->document_number;
$covernote_created_at = date('M d, Y', strtotime($data['covernote']->created_at));
$email = $covernote->closing_instruction->crm_contact->email;
SendEmailCovernote::dispatch($data, $email, $pdf, $doc_numb_covernote, $covernote_created_at);
}
注意:我正在使用库 dompdf 来生成 pdf 文件。