Reputation: 389
I have an excel file attachment and try to send an email. I'm able to send an email successfully, but I'm getting an error while opening the attached excel file which is given below:
error :-
"Excel cannot open the file "test.xlsx" because the file format or file extension is not valid.
Verify that the file has not been corrupted and that the file extension matches the format of the file."
Code:-
$WRKDIR="/tmp/xpyt/"
$EXCEL_FILE="test.xlsx"
$EMAIL_FROM="[email protected]"
$EMAIL_TO="[email protected]"
$EMAIL_SUBJECT="Excel Report"
$EMAIL_TYPE="multipart/mixed"
$msg = MIME::Lite->new(
From => $EMAIL_FROM,
To => $EMAIL_TO,
Subject => $EMAIL_SUBJECT,
Type => $EMAIL_TYPE,
);
$msg->attach(
Type => 'TEXT',
Data => "Here's the excel file you wanted"
);
chmod 0755, $EXCEL_FILE_PATH;
$msg->attach(
Type => 'application/vnd.ms-excel',
Path => $WRKDIR,
Filename => $EXCEL_FILE,
Disposition => 'attachment'
);
$msg->send();
Any help will be appreciated.
Upvotes: 1
Views: 850
Reputation: 3917
change Path => $WRKDIR
to Path => $WRKDIR.$EXCEL_FILE
and try again
path is the full path to your attachement, filename is the recommended filename to appear in the mail
Upvotes: 0
Reputation: 21619
application/vnd.ms-excel
is for BIFF (.xls
) files.
For Excel 2007 and above (.xlsx
) files, use:
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
(Source)
...so, either change your extension or the attachment type, so they match.
Upvotes: 1