我有一个网站,我在其中开发了一个 xls 报告。创建后,我想用 phpmailer 将其发送到邮件中。如何将此文件附加到电子邮件中?这是我的代码:
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Alessandro Minoccheri")
->setLastModifiedBy("Alessandro Minoccheri")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Generazione report inverter")
->setKeywords("office 2007 openxml php")
->setCategory("");
$row=1;
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow('0', $row, 'Inverter');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow('1', $row, 'Channel');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow('2', $row, 'Picco');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow('3', $row, 'Picco data');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow('4', $row, 'Media');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow('5', $row, 'Sommatoria');
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('report.xls');
$yourName = 'Client';
$yourEmail_2 = 'alessandro@xxx-it';
ini_set("include_path", "../inc/phpmailer/");
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->From = 'xxx@xxx.com';
$mail->FromName = 'Client';
$mail->AddAddress($yourEmail_2);
//$mail->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 = '<p>Curriculum allegato: '</p>';
}
}*/
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = 'Riepilogo settimanale';
$mail->Body = "Riepilogo settimanale dell'impianto: ".utf8_decode($inv['name']);
$mail->AltBody = "Riepilogo settimanale dell'impianto: ".utf8_decode($inv['name']);
if ( $mail->Send()){
//ok
}