2016-11-28 146 views
2

我知道這個問題之前已經被問過,但我顯然需要我的手。我正在嘗試將pdf附加到電子郵件併發送。我已經用PHPMailer在Laravel之外完成了它,但現在我正在嘗試Laravel的方式,無法實現它。我在這裏做錯了什麼?如何使用barryvdh/laravel-dompdf將PDF附加到Laravel的電子郵件中

這是我得到的錯誤的開始:

Swift_IoException在FileByteStream.php行144: 無法打開文件進行讀取[%PDF-1.3

public function attach_email($id){ 

    $info = Load::find($id); 

    $info = ['info'=>$info]; 

    Mail::send(['text'=>'mail'], $info, function($message){ 

     $pdf = PDF::loadView('pdf.invoice'); 

     $message->to('[email protected]','John Smith')->subject('Send Mail from Laravel'); 

     $message->from('[email protected]','The Sender'); 

     $message->attach($pdf->output()); 

    }); 
    echo 'Email was sent!'; 
    } 

回答

5

使用$message->attachData($pdf->output(), 'filename.pdf');代替$message->attach($pdf->output());

+0

非常感謝! – mcornille

相關問題