Okay, so I have tried to have a go at working out how to do this myself using google... I think I may have made the problem worse
I am getting the error "PHP Fatal error: Only variables can be passed by reference in /home/sqlqueries/Test.php on line 45". It is probably fair to say I have no idea what I am doing at the moment. Frankly, I am still at the stage on PHP where everything looks like another language. Help anyone?
At the moment, it just sends me an e-mail with an empty spreadsheet... along with an error in PuTTY.
<?php
putenv("TNS_ADMIN=/usr/lib/oracle/11.2/client64");
require_once "DB.php";
@$DB = oci_connect('#####','#####','domain');
if (DB::isError($DB))
{
echo 'Cannot connect to database: ' . $DB->getMessage();
}
else
{
$strPath = "domain";
$filName = "customer.csv";
$objWrite = fopen($strPath."/".$filName, "w");
$fromdate = strtotime("last Monday");
$todate = strtotime("last Sunday");
if($todate < $fromdate)
{
// subtract another week
$fromdate = strtotime("-1 weeks", $fromdate);
}
$fromdate = date('d/m/Y', $fromdate);
$todate = date('d/m/Y', $todate);
$body = "";
$body .= "<h3>For period " . $fromdate . " to " . $todate . "</h3>\n";
$Query = "SELECT DCONSUMER, DDATE, DTYPE, DAMT/100 AS DAMT, SUBSTR(DWHO,0,INSTR(DWHO,':')-1) AS DWHO, DREF, DEXTDESC
FROM UTILITY.DEBT
WHERE SUBSTR(DWHO,0,INSTR(DWHO,':')-1) IN
(
SELECT ID FROM UTILITY.USERS
WHERE USE_SEN = MANAGER'
)
AND DTYPE NOT IN ('CHG1','CHG2','CHG3','CHG4')
AND DDATE >= TO_DATE('".$fromdate."','dd/mm/yyyy')
AND DDATE <= TO_DATE('".$todate."','dd/mm/yyyy')
ORDER BY DAMT";
$objQuery = oci_parse($DB, $Query);
while($objResult = oci_fetch_all($objQuery, OCI_BOTH))
{
fwrite($objWrite, "\"$objResult[DCONSUMER]\",\"$objResult[DDATE]\",\"$objResult[DTYPE]\",\"$objResult[DAMT]\",\"$objResult[DWHO]\",\"$objResult[DREF]\",\"$objResult[DEXTDESC]\" \n");
}
fclose($objWrite);
//*************** Send Email ***************//
$strTo = "
[email protected]";
$strSubject = "CSV Report $fromdate - $todate";
$strMessage = "Download $filName for CSV Report for period $fromdate to $todate";
//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));
$strHeader = "";
$strHeader .= "From: Automation <
[email protected]>\nReply-To:
[email protected]\n";
$strHeader .= "Bcc:
[email protected]";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=windows-874\n"; // or UTF-8 //
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
$strContent1 = chunk_split(base64_encode(file_get_contents($strPath."/".$filName)));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$filName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$filName."\"\n\n";
$strHeader .= $strContent1."\n\n";
$flgSend = @mail($strTo,$strSubject,null,$strHeader); // @ = No Show Error //
}
?>