title: my CSV attachment is empty! PHP
body: <p>Im trying to take data from the database and display it in a CSV file which is both downloadable and emailed to someone. I have managed to get the downloadable file working and it displays all of the correct data. It also sends a CSV file to the necessary person but that CSV file is empty and no data is displayed in it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    $myroot = "../../";
      include($myroot . "inc/functions.php");
          // output headers so that the file is downloaded rather than 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 * FROM *****.*****';
  $surveys = db_query_into_array_enhanced($mysql_connection, $query);
  $count = count($surveys);
  $data = array();
      for($i=0; $i&lt;=$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 as $row )  
  {  
      fputcsv($output, $row, ',', '"');  
  }  
  fclose($output);  
  
  $encoded = chunk_split(base64_encode($output));
  
  // create the email and send it off
  
  $subject = "File you requested from RRWH.com";
  $from = "*****@*****.com";
  $headers = 'MIME-Version: 1.0' . "\n";
  $headers .= 'Content-Type: multipart/mixed;
     boundary="----=_NextPart_001_0011_1234ABCD.4321FDAC"' . "\n";
  
  $message = '
  
  This is a multi-part message in MIME format.
  
  ------=_NextPart_001_0011_1234ABCD.4321FDAC
  Content-Type: text/plain;
         charset="us-ascii"
  Content-Transfer-Encoding: 7bit
  
  Hello
  
  We have attached for you the PHP script that you requested from http://rrwh.com/scripts.php
  as a 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");
  </code></pre>
  
  <p>I've spent a day and a half on this but I cant see the problem. Could someone please point it out to me as to why the attached CSV file is empty?</p>
  
  <p>i'm getting kind of desperate and stressed out :( please someone help me.</p>