使用PHPMailer发送phpexcel文档
我试图在依赖phpexcel生成电子表格的脚本上使用phpMail 它完美地保存了电子表格,我没有收到PHP编译器错误,但它没有发送。如果没有发送或显示错误,我不确定会出现什么问题 以下是保存excel并生成邮件程序的部分:使用PHPMailer发送phpexcel文档,php,phpmailer,phpexcel,Php,Phpmailer,Phpexcel,我试图在依赖phpexcel生成电子表格的脚本上使用phpMail 它完美地保存了电子表格,我没有收到PHP编译器错误,但它没有发送。如果没有发送或显示错误,我不确定会出现什么问题 以下是保存excel并生成邮件程序的部分: $writer = PHPExcel_IOFactory::createWriter($phpExcel, "Excel2007"); $writer->save('Coaching Report - T
$writer = PHPExcel_IOFactory::createWriter($phpExcel, "Excel2007");
$writer->save('Coaching Report - Test.xlsx');
$mail = new PHPMailer(true);
//$address = "s";
$address = "omitted";
$date = date("D M d, Y");
try{
$mail->setFrom("omitted");
$mail->addAddress($address);
$mail->AddAttachment($writer,"Coaching Report $date.xlsx");
$mail->isHTML(true);
$mail->Subject = "Weekly Coaching Report";
$mail->Body = "Attached is the weekly coaching report for " . $date;
$mail->Send();
echo 'message sent';
} catch (Exception $e){
echo 'message failed';
echo 'mail error:' . $mail->ErrorInfo;
}
mysqli_close($conn);
您使用以下名称保存了excel文件:Coaching Report-Test.xlsx 但是,如果要附加此文件,请使用以下名称调用它:Coaching Report$date.xlsx
那是不对的。您必须使用现有文件名调用附件中的文件。Ah,当我在CSV文件上使用它时,我这样做是为了将今天的日期附加到它,我认为这在这里也适用。我现在就去试一试