1

I have a page with a preview of the receipt, it's dynamic rendering with tenants info and signature.

enter image description here

When I click test, the form will submit, triggering an email to myself.

I've tried

public function email($id){
    $code = Request::get('code'); 
    $baby = Baby::where('adminCode',$code)->where('id',$id)
    ->orWhere('readOnlyCode',$code)->where('id',$id)
    ->first();
    $input['name'] = 'John';

    if($baby){
        // $pdf = PDF::loadView('layouts.be.baby.email', get_defined_vars());
        $pdf = PDF::loadView('layouts.share.emails.thanks', get_defined_vars());
        $mail = Mail::to('layouts.share.emails.thanks', $baby, function($message)use($baby, $pdf) {
            $message->to('bheng@gmail.com')
            ->subject('Rent Receipt For'. date('m Y'))
            ->attachData($pdf->output(), date('m Y').".pdf");
        });
        if($mail) {
            return Redirect::to($_SERVER['HTTP_REFERER']) ->with('success','sent!');
        }
    }
}

See no error, also see no email.

How do I attach that receipt as an attachment in the email?

code-8
  • 54,650
  • 106
  • 352
  • 604
  • There's a handful of places to start but you could try [using mail() or PHPMailer](https://stackoverflow.com/questions/12301358/send-attachments-with-php-mail), or [Laravel Mailer](https://laravel.com/docs/5.1/mail#attachments). The issue you have is the display is in Javascript but you want the server side version. – hppycoder Apr 03 '21 at 18:23
  • There also might be a port for HTML2PDF you could try https://github.com/spipu/html2pdf that's written in PHP to get the export which you use one of the methods above to send the email – hppycoder Apr 03 '21 at 18:24

1 Answers1

0

https://laravel.com/docs/5.8/mail#attachments

Raw Data Attachments

return $this->view('emails.orders.shipped')
            ->attachData($this->pdf, 'name.pdf', [
                'mime' => 'application/pdf',
            ]);

}

code-8
  • 54,650
  • 106
  • 352
  • 604