Send CSV as attachment
Posted: Thu Dec 16, 2010 8:17 am
Hi,
I'm generating a CSV which outputs fine to the browser using a few headers()...
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...
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!
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;
Code: Select all
cron.php
$attachments = array(file_get_contents('csv.php'));
Can anyone advise on where I am going wrong?
Thanks in advance!