I have a script that currently takes some data from a wordpress DB and then loops over the returned rows and uses fputcsv(). The file handle was setup with:
$fh = fopen('php://output', 'w');
The script is linked to a link of a webpage and when you click the link it downloads the CSV (using the content-disposition header).
Is it possible to write to php://output this CSV file and then use PHP's mail() function to send it in an attachment?
I have a mail function I've written that will set the MIME type to multipart/mixed, I'm just not sure how to create the actual attachment to be emailed.