sql - Emailing CSV file with PHP -
i have extracted data database , displayed on webpage in table format. provided link on page allows user download data csv file. works correctly far , when user follows link beneath displayed data allows them save it.
it sends email csv attachment. currectly csv in attachment blank , dont know why.
all want data database placed downloadable csv go attached csv , cant it.
could me?
here code have far:
// create csv file fputcsv($output, array('name', 'branch', 'website','company', 'question1', 'question2', 'question3', 'question4', 'question5')); $mysql_connection = db_connect_enhanced('*******','******','******','******'); $query='select * ****.****'; $surveys = db_query_into_array_enhanced($mysql_connection, $query); $count = count($surveys); $data = array(); for($i=0; $i<=$count; $i++){ $data[] = array($surveys[$i]['feedbackname'], $surveys[$i]['branchname'], $surveys[$i]['feedbackwebsite'], $surveys[$i]['feedbackcompany'], $surveys[$i]['question1'], $surveys[$i]['question2'], $surveys[$i]['question3'], $surveys[$i]['question4'], $surveys[$i]['question5']); } foreach( $data $row ) { fputcsv($output, $row, ',', '"'); } $encoded = chunk_split(base64_encode($data)); // create email , send off $subject = "file requested rrwh.com"; $from = "***************"; $headers = 'mime-version: 1.0' . "\n"; $headers .= 'content-type: multipart/mixed; boundary="----=_nextpart_001_0011_1234abcd.4321fdac"' . "\n"; $message = ' multi-part message in mime format. ------=_nextpart_001_0011_1234abcd.4321fdac content-type: text/plain; charset="us-ascii" content-transfer-encoding: 7bit hello have attached php script requested http://rrwh.com/scripts.php zip file. regards ------=_nextpart_001_0011_1234abcd.4321fdac content-type: application/octet-stream; name="'; $message .= "surveys.csv"; $message .= '" content-transfer-encoding: base64 content-disposition: attachment; filename="'; $message .= "surveys.csv"; $message .= '" '; $message .= "$encoded"; $message .= ' ------=_nextpart_001_0011_1234abcd.4321fdac-- '; mail("*************", $subject, $message, $headers, "-f$from"); fclose($output);
it feels close cant see answer :(
change line:
$message .= "$encoded";
with one:
$message .= $encoded;
Comments
Post a Comment