Laravel将pdf文件附加到电子邮件中

问题描述 投票:1回答:2

我有一个问题是将系统中创建的官方信件附加到数据库中的讲师电子邮件中。

公共职能批准($ id,Request $ request){

    try {

        $letter = Letter::where('id',$id)
        ->update([
            'isApproved' => 1,
            'approvedBy' => $request->session()->get('users.id')
            ]);


        $letter = Letter::where('id',$id)
        ->first();

        $lecturer = User::where('id',$letter->user_id)
        ->get();

        $emailBody="Hello, ".$lecturer[0]->username.",<br>".
        "Your letter have been approved by ".$request->session()->get('users.username').".<br>".
        "Kindly check the attachment. Thank you.<br><br>".
        "This is system generated email. Please do-not reply on this email.";

        mail($lecturer[0]->email, "Certification Approved", $emailBody);

        return redirect()
        ->back()
        ->with('success_approve_letter','Record successfully approve');

    } catch (Exception $e) {

        return redirect()
        ->back()
        ->withErrors(["Error: ".$e->getMessage()]);
    }
}

但是在电子邮件中,它只是发送它。

Gmail Image

laravel pdf email-attachments
2个回答
0
投票

请通过link发送附件在php mail()或者你可以使用laravel email library发送电子邮件,这很容易


0
投票

Laravel的方式是使用Mailables。从the docs附加PDF文件的示例:

public function build()
{
    return $this->view('emails.orders.shipped')
                ->attach('/path/to/file', [
                    'as' => 'name.pdf',
                    'mime' => 'application/pdf',
                ]);
}
© www.soinside.com 2019 - 2024. All rights reserved.