1

I have a problem to attach official letter that have been create in the system which is in pdf to lecturer's email that have in the database.

public function approve($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()]);
    }
}

But in the email, it just send this.

Gmail Image

nnan
  • 11
  • 3

2 Answers2

0

Please go through the link to send attachment in php mail() or you can use laravel email library to send email ,that is quite easy

0

The Laravel way is to use Mailables. An example of attaching a PDF file from the docs:

public function build()
{
    return $this->view('emails.orders.shipped')
                ->attach('/path/to/file', [
                    'as' => 'name.pdf',
                    'mime' => 'application/pdf',
                ]);
}
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279