附件以“文件”格式而不是pdf下载

时间:2015-05-26 05:27:05

标签: pdf laravel-4 email-attachments file-format

我通过laravel发送带附件(pdf)的电子邮件。但下载后的附件转换为“文件”类型而不是pdf ...

继承我的代码

    $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'));
        });

我希望文件以pdf格式下载。我该怎么做?

1 个答案:

答案 0 :(得分:1)

找到解决方案。使用.pdf属性中的文件名添加as,如下所示:

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