代码之家  ›  专栏  ›  技术社区  ›  Geoff_S

使用PHPMailer发送phpexcel文档

  •  0
  • Geoff_S  · 技术社区  · 6 年前

    我试图在依赖phpexcel生成电子表格的脚本上使用phpmailer。

    它完美地保存了电子表格,我没有收到phpmailer错误,但它没有发送。我不确定如果它不发送 显示错误。

    以下是保存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);
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Vahid Moghadam    6 年前

    您使用以下名称保存了excel文件:Coaching Report-Test。xlsx

    但如果要附加此文件,请使用以下名称将其命名为:Coaching Report$date。xlsx

    这是错误的。必须使用现有文件名调用附件中的文件。