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

fichby's avatar

Laravel Vapor sending attachment with email

Hi

I need to send an email out with an excel attachment create from "laravel Excel"

this is all done at the same time

in the controller i have

Excel::store(new ConsumptionExport($this->vehicles), 'Consumptions.xlsx');

and in the mail class i have

return $this->from('[email protected]')->markdown('emails.consumptionreport')->attach(storage_path('Consumptions.xlsx'));

however in the logs on vapor i am receiving

Illuminate\Contracts\Filesystem\FileNotFoundException
10:03:41 AM
Unable to open file for reading [/tmp/storage/Consumptions.xlsx]
/var/task/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php:134

any help would be really appreciated.

0 likes
10 replies
Sinnbeck's avatar

I believe that excel stores them in 'storage/exports' but you are looking in 'storage' (it can be changed in excel.php config file)

return $this->from('[email protected]')->markdown('emails.consumptionreport')->attach(storage_path('exports/Consumptions.xlsx'));
fichby's avatar

I have checked on s3 bucket it is storing it in the root of s3 bucket

fichby's avatar

I have updated the error message as it was not showing the correct error.

Sinnbeck's avatar

Try using the storage helper

return $this->from('[email protected]')->markdown('emails.consumptionreport')->attach(Storage::path('Consumptions.xlsx'));
fichby's avatar

I am still getting the same error

Swift_IoException
10:51:04 AM
Unable to open file for reading [Consumptions.xlsx]
/var/task/vendor/swiftmailer/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php:131
Sinnbeck's avatar

Ok. A bit of googling let me to this. Untested as I dont have s3.

->attachFromStorageDisk('s3', 'Consumptions.xlsx');

If it does not work you might want to look into testing if you can get content from the files at all

dd(file_get_content(Storage::path('Consumptions.xlsx')));
fichby's avatar

Looks like attaching the path, and then making the file public worked.

Sinnbeck's avatar

Sounds good. I suggest marking your own working answer as best answer to make it easier for others to see the correct way of doing it :)

fichby's avatar
fichby
OP
Best Answer
Level 5

Will make the answer more explicit.

use this is the controller

Excel::store(new ConsumptionExport($this->vehicles), "Consumptions.xlsx");

and then in the mail class

$path = \Storage::url("Consumptionse.xlsx"); 
return $this->from('[email protected]')
            ->markdown('emails.consumptionreport')
            ->attach($path);

you will also have to set file as public on s3 bucket.

Please or to participate in this conversation.