Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KiwiFinn's avatar

How do I attach a file to a Notification email?

I'm trying to attach a file to an email Notification, Laravel 5.8

I don't want to use the Mailable class because I have a whole system built around these. I can attachFromStorage to a Mailable class and there is a function to attach a file to an email notification.

My files are stored locally. This works for Mailable

    public function build()
    {
        return $this->from('[email protected]',$this->staff->full_name)
                    ->attachFromStorage('library/code-conduct-2014.pdf')
                    ->markdown('emails.view');
    }

but if I try almost every variation I can think of, the following won't attach the same file to a mail notification (only showing the last portion of the mail notification)

                    ->attach('storage/app/library/code-conduct-2014.pdf',[
                      'as' => 'code-conduct-2014.pdf',
                      'mime' => 'application/pdf',
                    ]
                  );

Any ideas?

Thanks in advance.

0 likes
2 replies
EslamAhmed's avatar
Level 2

Yes, the function that you should use is attach, and it should look like this

public function toMail($notifiable)
{
        return (new MailMessage)
               ->line('Hello there')
               ->attach(storage_path() . "/app/library/code-conduct-2014.pdf");
}
4 likes
KiwiFinn's avatar

Thanks, that did the trick. Can't believe it was so easy and not really documented.

1 like

Please or to participate in this conversation.