Why does excel always gives me corrupted file every time i open the excel file that came from php

Why i can’t open the excel file that came from php.

header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8");
header("Content-Disposition: attachment; filename="$filename"");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header('Cache-Control: private',false);
echo esc($exceldata);

I tried using that but it’s always say:

Excel cannot open the file ‘filename.xlsx’ because the file format or file extension is not valid. Verify that the file has not been curropted and that the file extension matches the format of the file.

I tried changing the the filename in xls but it doesn’t work in excel app in smartphone.