This standalone PHP file runs a MySQL query. Then sends the results in an email as a CSV (comma separated values) file attachment. This CSV file is properly formatted so it can be opened by OpenOffice.org Calc, or Microsoft Excel.
Copyright © 2009 Stephen R. Owens
This software is licensed under the GNU GPL version 3.0.
I created this code as a standalone PHP file that can be run by opening it in a web browser, or running it from a Cron Job. The source code in this PHP file is well commented and can be modified to fit your needs. The GNU GPL license gives you the room to adapt it to your project.
What it does:
Some example of how others have used this file include:
A web server with PHP and a MySQL database.
You will need to know how to:
Step 1: Add your Server Information, and Personal Settings, to the Source Code
The source code is well documented and you will be able to figure out what to enter, and where to enter it, by following these directions:
Step 2: Upload the file to Your Web Sever
After you fill in your specific details, upload the file email-query-results-as-csv-file.php to your web server.
Setp 3: Run the File from a Web Browser
Run the file email-query-results-as-csv-file.php from a web browser. It will output messages of success or error at each step.
If you have questions on using this tool, or have a comment, you can contact me or post a message into the comments section below.
If you need helping modifying this file for a particular purpose, or integrating it with another PHP program, and you don't have the coding skills, I will code for money. Contact me for a quote.
2009-NOV-11: v1.0
* Initial Public Release
Copyright © 2001 - 2010, Stephen R. Owens, All rights reserved.
Comments for "Email MySQL Query Results as a CSV File Attachment"
Grazie
Im trying to modify the code in order to send N files por N querys. But I'm not sure if it is possible.
Do you understand the idea? Query 1 --> File1.csv ; Query2 --> File2.csv, etc...
For sure I could send N emails, but maybe this will be marked as SPAM.
I undestood how to create the CSV file, but I don't know if it possible to attach 2 or more files with the code.
Can you help me?
Attaching multiple files to one email is very possible. You would have to repeat the code found from lines 167 to Lines 181. These lines attach the CSV file. You will also have to modify the code in lines 167 to 181 to uniquely name each file attachment.
Lines 107 to 136 runs the query and builds the CSV file. Repeat these lines for each needed CSV file.
If you need help modifing the source, I sling code for money.
Leave a Comment