title: Creating excel file and then send as attachment using phpmailer
body: <p>I have gone through multiple documents for this question and have applied those steps but so far in vain. I have written a code for excel file but I want to get its contents in the same file and use them as an attachment of excel file using PHPMailer function. </p>
  
  <p>Below is the code I am using after creating excel file:</p>
  
  <pre><code>$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 
  $objWriter-&gt;save('php://output');
  
  $data = ob_get_contents();
  
  $email-&gt;SetFrom('sample@gmail.com', 'Talal Haider'); //Name is optional
  $email-&gt;Subject   = 'Test Mail';
  $email-&gt;Body      = 'Simple Test Email';
  $email-&gt;AddAddress( 'sample@gmail.com' );
  //$email-&gt;AddAddress( 'rimsha.cheema@gmail.com' );
  
  $email-&gt;AddAttachment($data, 'Inspection_Report.xls' );
  
  if($email-&gt;Send()){
      echo "Mail Sent";
  } else{
      echo "Mail Failed";
  }
  </code></pre>
  
  <p>Please guide me in the right direction. Thanks a lot</p>