I recently ran into trouble when upgrading my application from Laravel 6 to 7. I finally decided to create a fresh Laravel 7 application and to manualy import my Laravel 6 code into it. All works fine, except for this one thing and I can't get my head around it.
I use my application to create a PDF file and attach it to an email. The mail body is in fact a Blade template with some HTML code. This used to work fine, but now, whenever I attach a PDF file, the mail body shows the complete HTML code as plain text.
This is the build function of my Mail model:
public function build()
{
return $this->subject(trans('text.reminder_subject').' '.$this->invoice->invoice_number)
->replyTo('[email protected]', 'SebDev')
->attach(storage_path($this->invoice->invoice_number.'.pdf'))
->view('mails.reminder-mail')
->with([
'invoice' => $this->invoice,
'text' => $this->text
]);
}
This is my Blade code:
<!doctype html>
<head>
<meta charset="utf-8">
<title>Herinnering factuur {{ $invoice->invoice_number }}</title>
</head>
<body style='font-family:Segoe UI;'>
<div style='width:75%;margin:auto;'>
{!! nl2br($text) !!}
</div>
</body>
</html>
If I remove this part:
->attach(storage_path($this->invoice->invoice_number.'.pdf'))
The email renders fine, but obviously without the attachment. However, if this line is added, the attachment is sent with the email, but the email body contains the HTML code as plain text.
Any ideas about how to troubleshoot? Thanks!