Created
December 17, 2019 07:50
-
-
Save JudeRosario/11e41f0bb7fff806001296cf97e4465b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function emailPreviousMonthReportTo($To) | |
{ | |
global $wpdb; | |
//Get Last Months Report | |
$arrResult = $wpdb->get_results("SELECT `id`, | |
`date`, | |
`first_name`, | |
`last_name`, | |
`email`, | |
`business_name`, | |
`phone`, | |
`city`, | |
`country`, | |
`state`, | |
`joined_date`, | |
`product_title` FROM `".self::LOG_TABLE_NAME."` WHERE MONTH(`date`) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH) ORDER BY `date` DESC;"); | |
$CurrentMonth = date("F",strtotime("-1 month")); | |
$filepath = dirname(__FILE__) . '/TEIRockDrills_Brochures_'.$CurrentMonth.'.csv'; | |
$fileHandle = fopen($filepath, 'w'); | |
if($fileHandle === FALSE) { | |
die('Failed to open temporary file'); | |
} | |
fputcsv( $fileHandle, array('Entry ID', | |
'Date', | |
'First Name', | |
'Last Name', | |
'Email', | |
'Business Name', | |
'Phone', | |
'City', | |
'Country', | |
'State', | |
'Joined Date', | |
'Product Title')); | |
foreach ( $arrResult as $Entry ) { | |
$modified_values = array($Entry->id, | |
$Entry->date, | |
$Entry->first_name, | |
$Entry->last_name, | |
$Entry->email, | |
$Entry->business_name, | |
$Entry->phone, | |
$Entry->city, | |
$Entry->country, | |
$Entry->state, | |
$Entry->joined_date, | |
$Entry->product_title); | |
fputcsv( $fileHandle, $modified_values ); | |
} | |
rewind($fileHandle); | |
fclose($fileHandle); | |
$Subject = "TEIRockDrills Monthly Report - ".$CurrentMonth; | |
$Message = "Attached is the monthly report for the month of ".$CurrentMonth."."; | |
$Headers[] = 'From: TEI RockDrills <[email protected]>'; | |
$Attachments = array($filepath); | |
wp_mail( $To, $Subject, $Message, $Headers, $Attachments ); | |
// unlink($filepath); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment