title: create excel file from mysqli db, and addattachment() this file to mail()
body: <p>I am able to create the excel file, it is saved in the downloads folder.
  I am able to send the mail with the correct subject, body etc...
  The excel file isn't attaching in the mail, please help me on this.</p>
  
  <p>Edit : The AddAttachment() Statement returns false</p>
  
  <p>//php code below in  tags</p>
  
  <pre><code>include 'PHPExcel.php';
  
  require_once ("C:\\xampp\\htdocs\\excel_mailer\\PHPMailer-master\\class.phpmailer.php");
  
  $path           =   "C:\\Users\\Manish\\Downloads";
  $file_name      =   $_GET['file_name'];
  
  $DB_server      =   "localhost";
  $DB_username    =   "root";
  $DB_password    =   "";
  $DB_dbname      =   "timetracker";
  $DB_tablename   =   "tt_users";
  
  $conn           =   mysqli_connect ($DB_server, $DB_username, $DB_password, $DB_dbname);
  
  if (mysqli_connect_errno()) {
      die ("Connection Failed!");
  }
  
  $sql    =   "SELECT *";
  $sql    .=  " FROM $DB_tablename";
  
  if ($result = mysqli_query($conn,$sql));
  
  else die("Couldn't execute query:&lt;br /&gt;" . mysqli_error(). "&lt;br /&gt;" . mysqli_errno());
  
  $file_ending = ".xls";
  
  $filename = $file_name.$file_ending;
  
  header("Content-Type: application/vnd.ms-excel");
  header("Content-Disposition: attachment; filename=$filename");
  
  
  
  /*******Start of Formatting for Excel*******/
  
  $sep        = "\t"; //tabbed character
  $flag       = true;
  $col_names  = "";
  
  while($row = mysqli_fetch_assoc($result)) {
      $data_insert    = "";
              foreach($row as $field=&gt;$data) {
          if ($flag)
              $col_names      .= $field.$sep;
          if(!isset($data))
              $data_insert    .= "NULL".$sep;
          elseif ($data != "")
              $data_insert    .= $data.$sep;
          else
              $data_insert    .= "".$sep;
      }
  
      if ($flag) {
          $flag       = !$flag;
          $col_names  .= "\t";
          echo (trim($col_names));
          echo "\n";
      }
      $data_insert    .= "\t";
      echo (trim($data_insert));
      echo "\n";
  }
  
  $email = new PHPMailer();
  
  $email-&gt;From      = 'somevalid@email.address';
  $email-&gt;FromName  = 'Name';
  $email-&gt;Subject   = 'PFA excel file';
  $email-&gt;Body      = 'Regards';
  $email-&gt;AddAddress( 'somevalid@email.address' );
  
  $file_to_attach = $path."\\".$filename;
  
  //echo $path."\\".$filename;
  
  $email-&gt;AddAttachment( $file_to_attach );
  
  $email-&gt;Send();
  </code></pre>