Reputation: 341
I am working on sending email function. Firstly, I want to generate .pdf file from my view. Then I want to attach the generated .pdf file by email without saving it into disk. I use below in my controller:
$pdf = PDF::loadView('getpdf', $data);
Mail::to($to_email)->send(new Mysendmail($post_title, $full_name))
->attachData($pdf->output(), "newfilename.pdf");
And I get this error: "Call to a member function attachData() on null"
If I use below without attachment, it works well:
$pdf = PDF::loadView('getpdf', $data);
Mail::to($to_email)->send(new Mysendmail($post_title, $full_name));
Please advise.
Upvotes: 5
Views: 3333
Reputation: 17
Just use 'mime' => 'application/pdf', at last of your code. Simple!
$pdf = PDF::loadView('getpdf', $data);
Mail::to($to_email)->send(new Mysendmail($post_title, $full_name))
->attachData($pdf->output(), "newfilename.pdf"), [
'mime' => 'application/pdf',
]);
Upvotes: 1
Reputation: 17
Just use 'mime' => 'application/pdf', at last of your code. Simple!
` $pdf = PDF::loadView('getpdf', $data); Mail::to($to_email)->send(new Mysendmail($post_title, $full_name)) ->attachData($pdf->output(), "newfilename.pdf"), [ 'mime' => 'application/pdf', ]); `Upvotes: 0
Reputation: 2511
I think you need to attach it to the message, not to the mailer.
$pdf = PDF::loadView('getpdf', $data);
$message = new Mysendmail($post_title, $full_name);
$message->attachData($pdf->output(), "newfilename.pdf");
Mail::to($to_email)->send($message);
Upvotes: 9