mysql - PHP attachment in email is empty -
im trying take data database , display in csv file both downloadable , emailed someone. have managed downloadable file working , displays of correct data. sends csv file necessary person csv file empty , no data displayed in it.
here code:
$myroot = "../../"; include($myroot . "inc/functions.php"); // output headers file downloaded rather displayed header('content-type: text/csv; charset=utf-8'); header('content-disposition: attachment; filename=surveys.csv'); $output = fopen('php://output', 'w'); // 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, ',', '"'); } fclose($output); $encoded = chunk_split(base64_encode($output)); // create email , send off $subject = "file requested rrwh.com"; $from = "*****@*****.com"; $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("*****@*****.com", $subject, $message, $headers, "-f$from");
i've spent day , half on cant see problem. please point out me why attached csv file empty?
i'm getting kind of desperate , stressed out :( please me.
it have helped taking @ error logs or @ least setting
ini_set('error_reporting', e_all); ini_set('display_errors', 1);
as have told base64_encode expects string $output resource.
try setting
ob_start();
to beginning ,
$output = ob_get_flush();
between fclose & $encoded lines.
haven't tryed mail yet should @ least bit :)
i tryed code , worked well:
<?php ob_start(); header('content-type: text/csv; charset=utf-8'); header('content-disposition: attachment; filename=surveys.csv'); $output = fopen('php://output', 'w'); fputcsv($output, array('name', 'branch', 'website','company', 'question1', 'question2', 'question3', 'question4', 'question5')); $data = array(); $data[] = array('name', 'branch', 'website','company', 'question1', 'question2', 'question3', 'question4', 'question5'); foreach( $data $row ) { fputcsv($output, $row, ',', '"'); } fclose($output); $output = ob_get_flush(); $encoded = chunk_split(base64_encode($output));
Comments
Post a Comment