简体   繁体   中英

How can I send an email with a PDF with Laravel

I have a PDF coded in base 64, it is an attribute in my database, and I send emails through Laravel but I do not know how can I send the base64 as a PDF.

 public function toMail() { $pdf_decoded = base64_decode($this->table->raw_label); $message = (new MailMessage) ->subject(env('APP_NAME').' - HI #'. $this->order->id) ->greeting('¡Hi;'): if(env('APP_URL') == 'http.//test.test'){ $message->bcc(['test@test;com']); } return $message; }

I know attach property, but I do not know hot to implement it.

You can actually do this through the Mail or Notification class, personally I would use a Notification but it's up to you. Just use the ->attach($pathToFile) method and give it the file path as a parameter.

Here's an example using a Notification , hope this helps!

/**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('Please download the PDF.')
                    ->attach(public_path($this->filename), [
                        'as' => 'filename.pdf',
                        'mime' => 'text/pdf',
                    ]);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM