phplaravellaravel-mail

Laravel Mail attach method - Attached file not opening after downloading


I have used the Laravel Mail attach method to specify file attachment for the mail being sent. The file attached successfully but cannot be viewed.

->attach(route('download_attachment', 'file=' . $attachment->name));

One thing I noticed though is that if I generate the link in the email being sent, people can also only download it if they are authenticated. So, I am thinking it has something to do with auth/role as the files are stored in the Storage on the server not public_html


Solution

  • I have solved this still with help from Stackoverflow though. I first get the actual file from the storage, then I attached it as shown below.

    $getThisFile = storage_path('app/' . $attachment->name);

        return (new MailMessage)      
                    ->subject('Download Ready')              
                    ->line('Some texts')
                    ->line('Thank you!')
                    ->attach($getThisFile);