The code works fine and I receive the data. However I can't get the script to send the file as a .CSV file. I have tried using the "text/csv" and "text/comma-separated-values" MIME types and both send the file as a .txt file. Using the "application/vnd.ms-excel" MIME type it sends the file as an XLS file which doesn't display the file correctly.

Am I doing something wrong? How can I get the PHP script to attach the file as a .csv file?

Any help would be greatly appreciated!

Thanks,Michael

PCSpectra
—
2009-07-20T18:46:38Z —
#2

First thing I would do is use a a proper mailer, like SwiftMailer, instead of constructing the headers, etc yourself, just manipulate an easy API and voila.

blubb
—
2009-07-20T18:52:49Z —
#3

There are a lot of errors in your code:- Some \ are wrong or missing.- Use Punycode for e-mail-adresses.- Use mb_encode_mimeheader for subject.- Add Content-Disposition info.- And all data must be put into the header.

Finally mail must look like:

mail('xxx@yyy.de','subject','',$headerData)

Google: php mail attachments

I think, csv-files are not binary-files. So I would not use 'b'.file_get_contents ist easier than fopen....

For testing:- don´t use any @- At the beginning of your script: error_reporting(E_ALL|E_STRICT);

Bytecon
—
2009-07-22T16:01:47Z —
#4

Does anyone have any idea on the MIME type issue? I understand the code may not be perfect but it sends an email fine, its just configuring it to send it as a .csv file im having trouble with.

Mark_Baker
—
2009-07-22T16:17:48Z —
#5

MIME type is text/plain or text/csv for CSV files

Bytecon
—
2009-07-22T16:21:14Z —
#6

Thanks for your reply Mark, when I use text/plain or text/csv to send the file as an attachement using the code above it sends the file attached as a .txt file, do you know anyway to get it to send as a .csv file?

Mark_Baker
—
2009-07-22T17:16:10Z —
#7

Bytecon said:

Thanks for your reply Mark, when I use text/plain or text/csv to send the file as an attachement using the code above it sends the file attached as a .txt file, do you know anyway to get it to send as a .csv file?