$tableName = ‘lead’;
$query = “SELECT DISTINCT * FROM $tableName where DATEDIFF(NOW(), date_created) <= $defaultEndDate”;
$result = $this->mysqli->Query($query);
$row_count = $result->Row_Count();
$fileName = “lead.csv”;
$fp = fopen("$fileName.csv", “w”);
fputcsv($fp, array(“Date/Time of Application”, “First Name”, “Middle Initial”, “Last Name”, “Address 1”, “Address 2”, “City”, “State/Province”, “Postal Code”, “Country”, “Email Address”, “Home Phone”, “Mobile Phone”, “Employer Name”, “Work Phone”, “Extension”, “Personal Reference First Name”, “Personal Reference Last Name”, “Nature of Relationship”, “Phone Number”));
while ($row = $result->Fetch_Array_Row(MYSQLI_ASSOC))
{
$personal = array($row[‘date_created’]);
$json = json_decode($row[‘json_response’], true);
$response = array($json[‘firstName’], $json[‘middleInitial’], $json[‘lastName’], $json[‘address1’], $json[‘address2’], $json[‘city’], $json[‘state’], $json[‘zip’], $json[‘country’], $json[‘email’], $json[‘homePhone’], $json[‘mobilePhone’], $json[‘employer’], $json[‘workPhone’], $json[‘workPhoneExt’], $json[‘ref1-firstName’], $json[‘ref1-lastName’], $json[‘ref1-relationship’], $json[‘ref1-phone’]);
fputcsv($fp, array_merge($personal, $response));
}
fclose($fp);
$recipients = "[email protected]";
$body = “Attached is the new report.\r\n\r\n”;
$contents = file_get_contents($fileName);
$attachments[] = array(
‘method’ => ‘ATTACH’,
‘filename’ => $fileName,
‘mime_type’ => ‘text/plain’,
‘file_data’ => gzcompress($contents),
‘file_data_length’ => strlen($contents),
);
$subject=“International Lead Report”;
if (($row_count > 0)) {
sendMessage($recipients, $body, $subject, $attachments);
}