【发布时间】:2019-12-10 12:49:06
【问题描述】:
我无法将任何变量从 Controller 传递给电子邮件正文。我已经搜索了很多解决方案,但没有一个与我匹配。
我正在使用 Mailable。但它是空的。我不确定它是否会造成问题。
public function __construct(){}
public function build(){}
我在没有传递变量的情况下使用虚拟电子邮件进行了测试。电子邮件发送成功。所以,我认为配置没有问题。
控制器中的功能:
public function mail()
{
$info = Invoice::find(65)->first();
// 65 is giving me value. I have checked with dd()
$data = [
'invoice' => $info->invoiceNumber
];
Mail::send(['text'=>'invoice.test'], $data, function($message) use($data){
$pdf = PDF::loadView('invoice.test');
$message->to('example@gmail.com','John Smith')->subject('Send Mail from Laravel');
$message->from('from@gmail.com','The Sender');
$message->attachData($pdf->output(), 'Invoice.pdf');
});
return 'Email was sent';
}
test.blade.php
<h1>It is working!! {{ $invoice }}</h1>
【问题讨论】:
-
use($data,$pdf)你的 $pdf 变量是未定义的,因为你没有使用它。 -
已使用。但同样的错误。
标签: laravel laravel-mail