title: PHPExcel send file in email
body: <p>I have a site where in a page I have developed an xls report.
  After its creation I want to send it in a mail with phpmailer.
  How can I attach this file to the email?
  This is my code:</p>
  
  <pre><code>    $objPHPExcel = new PHPExcel();
  
              // Set document properties
              $objPHPExcel-&gt;getProperties()-&gt;setCreator("Alessandro Minoccheri")
                                           -&gt;setLastModifiedBy("Alessandro Minoccheri")
                                           -&gt;setTitle("Office 2007 XLSX Test Document")
                                           -&gt;setSubject("Office 2007 XLSX Test Document")
                                           -&gt;setDescription("Generazione report inverter")
                                           -&gt;setKeywords("office 2007 openxml php")
                                           -&gt;setCategory("");
  
              $row=1;
              $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow('0', $row, 'Inverter');
              $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow('1', $row, 'Channel');
              $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow('2', $row, 'Picco');
              $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow('3', $row, 'Picco data');
              $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow('4', $row, 'Media');
              $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow('5', $row, 'Sommatoria');
  $objPHPExcel-&gt;setActiveSheetIndex(0);
  
          $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
          $objWriter-&gt;save('report.xls');
  
                 $yourName = 'Client';
          $yourEmail_2 = 'alessandro@xxx-it';
  
          ini_set("include_path", "../inc/phpmailer/");
          require("class.phpmailer.php");
          $mail = new PHPMailer();
  
          $mail-&gt;From     = 'xxx@xxx.com';
          $mail-&gt;FromName = 'Client';
          $mail-&gt;AddAddress($yourEmail_2); 
          //$mail-&gt;AddBCC($yourEmail_2); 
  
          /*if(!empty($_FILES['attachment']['tmp_name'])){
              $new_name = urlencode( rand(0,10000).rand(10000,20000).$_FILES['attachment']['name'] );
              if(move_uploaded_file($_FILES['attachment']['tmp_name'],'./uploads/'.$new_name)){
                  $string_file = '&lt;p&gt;Curriculum allegato: '&lt;/p&gt;';
              }
          }*/
  
          $mail-&gt;WordWrap = 50;                              // set word wrap
          $mail-&gt;IsHTML(true);                               // send as HTML
  
          $mail-&gt;Subject  =  'Riepilogo settimanale';
  
          $mail-&gt;Body     =  "Riepilogo settimanale dell'impianto: ".utf8_decode($inv['name']);
  
          $mail-&gt;AltBody  =  "Riepilogo settimanale dell'impianto: ".utf8_decode($inv['name']);
  
          if ( $mail-&gt;Send()){
              //ok
          }
  </code></pre>