2014-04-03 36 views
1

我試圖將一個PDF文件附加到我在Laravel 4中的外發電子郵件中,但似乎無法使其正常工作。此設置不會返回任何錯誤或任何內容,只需停在空白屏幕即可。電子郵件服務器設置是正確的,刀片視圖工作正常。 PDF創作者也在工作。在Laravel 4中使用SwiftMailer 4連接動態文件

我在這裏做錯了什麼?我對Laravel和PHP非常陌生。感謝您提供任何幫助或指導!

public function getPdf() 
{ 
    // YOU NEED THIS FILE BEFORE YOU CAN RUN DOMPDF 
    define('INCLUDE_PATH', '/home/dsimedic/apm/vendor/dompdf/dompdf'); 
    @ini_set("include_path", INCLUDE_PATH); 
    require_once('dompdf_config.inc.php'); 

    // grab session data passed from the redirect 
    $apmformdata = Session::get('apmform'); 

    // render the page with the correct data passed in 
    $html = View::make('formPdf') 
     ->with('apmformdata', $apmformdata); 

    // setup and generate the PDF 
    $dompdf = new DOMPDF(); 
    $dompdf->load_html($html); 
    $dompdf->render(); 
    $pdf = $dompdf->output(); 

    // download the file to the server. 
    $file_to_save = './pdf/'.$apmformdata->JobNumber.'.pdf'; 
    file_put_contents($file_to_save, $pdf); 

    // route the followup response based on the id status 
    if (($apmformdata->id) != "") 
    { 
     // set the message displayed 
     $status = 'updated'; 

     // send out the confirmation email with attached PDF 
     Mail::later(20,'emails.formFollowup', array('status'=>$status, 'JobNumber'=>$apmformdata->JobNumber), function($message) { 
      $message->to('[email protected]', 'My Name') 
       ->subject('APM Form Alert Notice') 
       ->attach(use ($file_to_save)); 
     }); 
    } 
    else 
    { 
     // set the message displayed 
     $status = 'created'; 
    } 

    // send user back to the homepage with success message 
    return Redirect::to('/') 
     ->with('flash_notice', 'APM Form: '.$apmformdata->JobNumber.' has been '.$status.'! <br/>You will recieve an email with a PDF copy of the form shortly!'); 
} 
+0

最終代碼。 – Kevin

回答

0

看起來你是不是通過你的文件,關閉:用於郵件(去除原來使用)以及用於安東尼奧的片段

Mail::later(20,'emails.formFollowup', array('status'=>$status, 'JobNumber'=>$apmformdata->JobNumber), function($message) use ($file_to_save) { 
     $message->to('[email protected]', 'My Name') 
      ->subject('APM Form Alert Notice') 
      ->attach(use ($file_to_save)); 
    });