【问题标题】:Attach TCPDF to mail in Laravel将 TCPDF 附加到 Laravel 中的邮件
【发布时间】:2019-05-27 16:08:27
【问题描述】:

我想在不保存的情况下附加使用 tcpdf 库生成的 pdf。 我可以附加生成的 pdf,但它已损坏。

我搜索了很多示例,但似乎都不起作用

这是我的代码:

public function index($id) {
    $viaje = Viaje::find($id);
    $users = User::orderBy('id', 'asc')->get();
    // usersPdf is the view that includes the downloading content
    $view = \View::make('usersPdf', ['viaje' => $viaje, 'users' => $users]);
    $html_content = $view->render();
    // Set title in the PDF
    PDF::SetTitle("List of users");
    PDF::AddPage();
    PDF::writeHTML($html_content, true, false, true, false, '');

    //PDF::Output('userlist.pdf');
    $fileatt = PDF::Output($name='yourfilename.pdf', $dest='E');

    $pdf = chunk_split($fileatt);

    $contactopro = Contactoviajespro::find($id);

    $data = [
        'link' => 'http://',
        'contacto' => $contactopro->name,
    ];


    Mail::send('emails.notificacion', $data, function($msg) use($pdf) {
        $msg->from('administracion@buendialogistica.com', 'Javier');
        $msg->to('xavieeee@gmail.com')->subject('Notificación');

        $msg->attachData($pdf, 'orden.pdf');

    });

    return redirect()->route('home')
                    ->with(['message' => 'Email enviado correctamene']);
}

【问题讨论】:

    标签: laravel tcpdf


    【解决方案1】:

    使用 "S" 生成 pdf,不要执行 chunk_split(),Laravel 会这样做。此外,如果您使用 queue() 而不是 send(),它将因附件而失败。要排队,请编写一个作业并与作业队列一起发送。

    【讨论】:

      猜你喜欢
      • 2015-12-26
      • 2017-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-29
      • 1970-01-01
      • 2012-05-28
      相关资源
      最近更新 更多