Trisha Posted March 18, 2011 Share Posted March 18, 2011 Hi, I have the program which get's the results from the database and allows download of the info in .csv format. Now I want to be able to mail this file as an attachment to an email address using gmail server. I've come up with a mail program which can mail the info from database in text format... need help in modifying it to send csv attachment. Any help is greatly appreciated. Thanks in advance!! [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/231036-php-mail-csv-file-attachment/ Share on other sites More sharing options...
ocpaul20 Posted March 18, 2011 Share Posted March 18, 2011 post a snippit of code that has the problem. then we can whizz in, see what the problem is, tell you and whizz out again. The forum is for code problems not whole problem solving. Link to comment https://forums.phpfreaks.com/topic/231036-php-mail-csv-file-attachment/#findComment-1189353 Share on other sites More sharing options...
Trisha Posted March 21, 2011 Author Share Posted March 21, 2011 that's weird.. I thought I attached the code anyway, I'll paste it here again... Thanks for the response!! <?php // Connect to the database server $dbcnx = @mysql_connect("localhost", "root", ""); if (!$dbcnx) { echo( "<P>Unable to connect to the " . "database server at this time.</P>" ); exit(); } // Select database if (! @mysql_select_db("adcol") ) { echo( "<P>Unable to locate " . "database at this time.</P>" ); exit(); } // Request data $result = mysql_query( "SELECT usertype,COUNT(name) as data FROM jos_users GROUP BY usertype"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } $num_fields = mysql_num_fields($result); $headers = array(); $fp = fopen('php://output', 'w'); if ($fp && $result) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="export.csv"'); header('Pragma: no-cache'); header('Expires: 0'); fputcsv($fp, $headers); while ($row = mysql_fetch_assoc($result)) { fputcsv($fp, array_values($row)); } die; } ?> Link to comment https://forums.phpfreaks.com/topic/231036-php-mail-csv-file-attachment/#findComment-1190496 Share on other sites More sharing options...
Trisha Posted March 21, 2011 Author Share Posted March 21, 2011 The above code downloads the csv file.... as "export.csv".... I need help with the mail function that attaches the above downloaded file and sends to a particular email address... I've tried plenty but can't even seem to get close Link to comment https://forums.phpfreaks.com/topic/231036-php-mail-csv-file-attachment/#findComment-1190500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.