I have data in a MySQL database. I am sending the user a URL to get their data out as a CSV file.
I have the e-mailing of the link, MySQL query, etc. covered.
In addition to all already said, you might need to add:
header("Content-Transfer-Encoding: UTF-8");
It's very useful when handling files with multiple languages in them, like people's names, or cities.