【问题标题】:Using SwiftMailer with Laravel 4 Attach Dynamic Files使用 SwiftMailer 和 Laravel 4 附加动态文件
【发布时间】:2014-04-03 13:20:10
【问题描述】:

我正在尝试在 Laravel 4 中将 PDF 文件附加到我的外发电子邮件中,但我似乎无法使其正常工作。此设置不会返回任何错误或任何内容,只会在空白屏幕上停止。电子邮件服务器设置正确,并且 Blade 视图工作正常。 PDF 创建器也在工作。

我在这里做错了什么?我对 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('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!');
}

【问题讨论】:

  • 用于邮件的最终代码(删除了原来的 USE)并使用了 Antonio 的 sn-p。

标签: php laravel laravel-4 swiftmailer


【解决方案1】:

看起来您没有将文件传递给闭包:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 2014-08-06
    • 2014-09-25
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多