문제

I am trying to attach a PDF file to my outgoing emails in Laravel 4, but I cannot seem to get it working correctly. This setup doesn't return any errors or anything, just stops at a blank screen. The email server settings are correct and the Blade view is working fine. The PDF creator is working too.

What am I doing wrong here? I am very new to Laravel and PHP. Thank you for any help or guidance you can provide!

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('name@domain.com', '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!');
}
도움이 되었습니까?

해결책

Looks like you are not passing your file to the closure:

   Mail::later(20,'emails.formFollowup', array('status'=>$status, 'JobNumber'=>$apmformdata->JobNumber), function($message) use ($file_to_save) {
        $message->to('name@domain.com', 'My Name')
            ->subject('APM Form Alert Notice')
            ->attach(use ($file_to_save));
    });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top