Page 1 of 1

Send CSV as attachment

Posted: Thu Dec 16, 2010 8:17 am
by mikeeeeeeey
Hi,

I'm generating a CSV which outputs fine to the browser using a few headers()...

Code: Select all

csv.php

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=users.csv");
header("Content-Type: text/csv");
echo $output;
exit;
This gets downloaded if accessed directly by the browser, which is great. However I wish to send this file via WordPress' wp_mail() function. This accepts any file attachments as an array, only thing is I cannot figure out how to send the final CSV...

Code: Select all

cron.php

$attachments = array(file_get_contents('csv.php'));

The above doesn't work and I've also tried readfile(), and amending the headers in the csv.php file.

Can anyone advise on where I am going wrong?

Thanks in advance!