使用PHPMailer给phpexcel doc发邮件
Using PHPMailer to mail phpexcel doc
我正在尝试在依赖 phpexcel 生成电子表格的脚本上使用 phpmailer。
它完美地保存了电子表格,我没有收到 php 邮件程序错误,但它没有发送。如果它不发送 或 显示错误,我不确定会出现什么问题。
这是保存 excel 并生成邮件程序的部分:
$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 文件:辅导报告 - Test.xlsx
但是当要附加此文件时,请使用此名称调用它:Coaching Report $date.xlsx
这是不正确的。您必须使用现有文件名调用附件中的文件。
我正在尝试在依赖 phpexcel 生成电子表格的脚本上使用 phpmailer。
它完美地保存了电子表格,我没有收到 php 邮件程序错误,但它没有发送。如果它不发送 或 显示错误,我不确定会出现什么问题。
这是保存 excel 并生成邮件程序的部分:
$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 文件:辅导报告 - Test.xlsx
但是当要附加此文件时,请使用此名称调用它:Coaching Report $date.xlsx
这是不正确的。您必须使用现有文件名调用附件中的文件。