Search code examples
pdflaravel-4email-attachmentsfile-format

Attachment downloaded in "File" format instead of pdf


I am sending an email with an attachment (pdf) through laravel.But the attachment when downloaded converts to "File" type instead of pdf...

Heres my code

    $pdf_file_path = public_path() . '/user/invoices/invoice_' .    $data['hp_transaction_id'] . '.pdf';
        PDF::loadView('payment.payment-invoice', $data)
                ->setPaper('a4')
                ->setOrientation('portrait')
                ->setWarnings(false)
                ->save($pdf_file_path);


 Mail::send('emails.view-property-transaction-completed', $data, function($message) use ($pdf_file_path, $transaction) {
            $message->to(Auth::user()->email)->subject('Transaction Completed');
            $message->attach($pdf_file_path, array('as' => 'Invoice-' . $transaction->id, 'mime' => 'application/pdf'));
        });

I want the file to get downloaded in pdf format.What should i do for that?


Solution

  • Found the solution. Add .pdf with the file name in as attribute, like this:

    $message->attach(
        $invoice_path, 
        array('as' => 'Invoice-' . $transaction->id. ".pdf", 'mime' => 'application/pdf')
    );