2014-04-03 4 views
1

Я пытаюсь прикрепить файл PDF к моим исходящим письмам в Laravel 4, но я не могу заставить его работать правильно. Эта настройка не возвращает никаких ошибок или ничего, просто останавливается на пустом экране. Настройки сервера электронной почты верны, и режим Blade работает нормально. Создатель PDF тоже работает.Использование SwiftMailer с Laravel 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

Окончательного кода, используемый для почты (удален оригинальный USE) и фрагмента подержанного Антонио. – 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)); 
    }); 
Смежные вопросы