Hi All
I am trying to use the spreadsheet writer and php mailer at the same time i want to fetch data from a table and email it in a form of an attachment , the attachment must be in a form of a spreadsheet
My email is being sent successfully but i am not getting an attachment , pls help me out.here is my code
[code=php]<?php
require_once (‘paths.php’);
require (CONNECTIONS.’conn.php’);
// processing finished, lets create the system logs (if there are any) and e-mail them
require_once (“Spreadsheet/Excel/Writer.php”);
require (CLASSES.’class.phpmailer.php’);
require(CLASSES.’class.smtp.php’);
$sql = “SELECT DISTINCT(Email_Address) FROM Internal_Docs_email_users”;
$selresult = mysql_query($sql);
while($rec=mysql_fetch_array($selresult)) {
$email = $rec[“Email_Address”];
$xlsName = “DocProc-results_”.$email.”.xls”;
$xls = new Spreadsheet_Excel_Writer($xlsName);
$sheet =& $xls->addWorksheet(‘Doc Proc’);
$sheet->setColumn(0, 0, 15);
$sheet->setColumn(2, 2, 80);
$sql = “SELECT Waybill_Date ,WaybillNumber, Customer_Reference, To_Ops_Branch, Route, Account_Number, Customer_Name, Service_Type, Scan_Back_Reason_Code, POD_Date, Date_Invoice_Received FROM Internal_Docs_waybills_outstanding”;
$selres = mysql_query($sql);
$count = 0;
while($rec2=mysql_fetch_array($selres)) {
$sheet->write($count, 0, $rec2[“WaybillNumber”]);
if ($rec2[“Submitted”])
$sts = “Uploaded”;
else
$sts = “Failed”;
$sheet->write($count, 1, $sts);
$sheet->write($count, 2, $rec2[“Waybill_Date”]);
$count++;
}
$xls->close();
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = “10.0.0.3”;
$mail->From = “Thikho”;
$mail->FromName = “Nikita”;
$mail->Sender = “”Nikita” “;
$mail->AddAddress($email);
$mail->Subject = “Doc Proc Returned “;
$mail->Body = “HinnPlease find attached an Excel spreadsheet containing results for the returned Doc Proc.nnRegardsnNikita IT”;
$mail->WordWrap = 50;
$mail->AddAttachment($xlsName);
if (!$mail->Send()) {
echo $mail->ErrorInfo;
}
try {
exec(“mv “.$xlsName.” /var/www/test/excel”);
}
catch (Exception $err) {
}
}
?>