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

ftiersch's avatar
$filename = '.xlsx';
        
Excel::store(new UsersExport, $filename);
        
$path = storage_path($filename);

Try giving it an actual filename, not just an extension.

'report.xlsx' for example

vandan's avatar
Level 13

@FTIERSCH - yes i try this

$filename = "Sales Register 2019 Cr.xlsx";
    
Excel::store(new UsersExport,$filename);
    
$path = storage_path($filename);

yes mail was sent but excel file correupted not valid extesnion like error while excel file open

vandan's avatar
Level 13

@FTIERSCH - here is my full code

$filename = "Sales Register 2019 Cr.xlsx";
    
Excel::store(new UsersExport,$filename);
    
$path = storage_path($filename);

$data = array('name'=>"byte and bits");      
    
\Mail::send('front.mail', $data, function($message) use($path){
        
    $message->to('[email protected]')
                
        ->subject('Sales Register 2019 Excelsheet');
        
    $message->from('[email protected]','byte and bits');
        
    $message->attach($path); 
    

});

ftiersch's avatar

Can you open the file that gets saved on your harddrive?

vandan's avatar
Level 13

@FTIERSCH - yes file is open

when i try to open excel file

error like "excel cannot open file 'sales register.xlsx' beacuse the file format or file extension is not valid. verify that the file extesnion matches the format of the file"

like error

ftiersch's avatar

Yes, but that error comes only when you open the file in the email or also when you open the file it saved on your disk?

jlrdw's avatar

Forget all about Excel for a minute try to send any file just practice sending email correctly first, with an attachment.

Maybe you're trying to cram too much into one operation.

After you can definitely email an attachment then the next step is to practice importing an Excel file but do not attempt to do anything else yet.

Just make sure you have imported correctly and can read the file nothing else yet.

Then and only then send it as an attachment.

That Github package has been around for a while, so if you slow down and just work those examples slowly you will learn this stuff.

By time this post has had so many questions and answers you could have worked several of the examples and learned.

And above, I mean import or export or whatever.

vandan's avatar
Level 13

@JLRDW - simple attachment successfully send but while i try export file send mail error popup

ftiersch's avatar

"exactly" is not an answer to an "or" question ;) Which one is it?

vandan's avatar
Level 13

@FTIERSCH - file open in mail or disk then error fetch

error like "excel cannot open file 'sales register.xlsx' beacuse the file format or file extension is not valid. verify that the file extesnion matches the format of the file"

vandan's avatar
Level 13

@FTIERSCH - my file export sucessfully

but i send file in mail then mail file downlaod and like issue error fetching

ftiersch's avatar

So you can open the exported file inside your Laravel directory?

vandan's avatar
Level 13

@FTIERSCH - no i exported file in public folder not in laravel directory

actually i found problem is mail

i try to mail send but not currect path to store file then is error is curreputed file message

problem is in code

$filename = "Sales Register 2019 Cr.xlsx";
    
Excel::store(new UsersExport,$filename);
    
$path = storage_path($filename);
    
dd($path);

i try dd to display "D:\laragon\www\hello\storage\Sales Register 2019 Cr.xlsx"

not file fetch only storage path fetch

actually i try to fetch exported file

vandan's avatar
vandan
OP
Best Answer
Level 13

@SNAPEY - i actually my mistake i cannot properly understand maatwebsite packages for readymate code

to how to store see

Excel::store(new UsersExport(2018), 'Sales Register 2019 Cr.xlsx');

readymate code but i am new in laravel so i cannot properly understand how its work

sorry @snapey @jlrdw @ftiersch

thanks for helping and guiding as

melx's avatar

@van1310 ,

Kindly can you paste all code the way you import file and send email with attachment

I have the same case.

1 like
Previous

Please or to participate in this conversation.