How to send email with uploaded files attached In Laravel

Categorized as Laravel Tagged

Laravel tip: if you want to send emails having user uploaded files attached, you don’t need to save the file first. Instead, you just attach the uploaded file with attachData method and that’s it! Here is the example from a Mailable class:

public function build()
{
  return $this->subject('Inquiry')
    ->to('[email protected]')
    ->markdown('email.inquery')
    ->attachData(
        $this->file,
        $this->file->getClientOriginalName(),
    );
}

Via @ecrmnn.

Leave a reply

Your email address will not be published. Required fields are marked *