I have the following:
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_start();
$objWriter->save("php://output");
$xlsData = ob_get_contents();
$xlsData1= "data:application/vnd.ms-excel;base64,".base64_encode($xlsData);
ob_end_clean();
        //Require for mailing functionality
        require_once('../../PHPMailer/PHPMailer-master/class.phpmailer.php');
        //Send mail function
        $mail= new PHPMailer(); // defaults to using php "mail()"
        $sender ="emailadddress";
        $mail->SetFrom($sender);
        $mail->AddAddress('emailaddress');   
        $mail->Subject="Combined repair and production report from ".$reportDate;
        $encoding = "base64"; 
        //$type = "image/png";
        $mail->AddStringAttachment(base64_decode($xlsData1), "combined_report".$reportDate."xlsx");  
        //$mail->AddAttachment($xlsData, $filename);
        $message= "Please see attached combined report";
        $message = "</body></html>";              
        $mail->MsgHTML($message);    
        if(!$mail->Send()) 
        {
            $response =  array(
                'op' => 'failed',
                'file' => "data:application/vnd.ms-excel;base64,".base64_encode($xlsData)
            );
        } 
        else 
        {
            $response =  array(
                'op' => 'ok',
                'file' => "data:application/vnd.ms-excel;base64,".base64_encode($xlsData)
            );
        } 
die(json_encode($response));
pg_close($conn);
this sends an email with an attachemnt but the attachment is a blank file. When I try to save it it has the filename and the extension like this: "filenamexlsx" so it looks like it is not getting the correct xlsx format. I have tried this too:
$mail->AddStringAttachment("data:application/vnd.ms-excel;base64,".base64_encode($xlsData);  
I have also tried:
    $encoding = "base64"; 
    $type = "application/vnd.ms-excel"; // and :application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
    $mail->AddStringAttachment(base64_decode($xlsData1), "combined_report".$reportDate."xlsx",$encoding,$type);
I also tried using the AddAttachment() instead of the string attachment and there is no attachment on the email when I do that.
I have followed : php send e-mail with attachment
and have also looked at multiple things out there like PHPMailer, AddStringAttachment and Data URI Scheme
but it doesnt appear to be working :( any help will be appreciated!
 
     
    