options['weekly_reports']['timestamp'] <= time()) && $send_email){
return;
}
if(!function_exists('gosmtp_group_by')){
include_once GOSMTP_PRO_DIR .'/main/email-reports.php';
}
$logger = new GOSMTP\Logger();
$week = $gosmtp->options['weekly_reports']['weekday'];
$last_week = date("Y-m-d", strtotime('last '.$week, strtotime('tomorrow')));
$start = date('Y-m-d', strtotime($last_week. ' -7 days'));
$end = $last_week;
$multiselect = array('subject');
$options = array(
'interval' => array(
'start' => $start,
'end' => $end
),
'pagination' => false,
);
$email_logs = $logger->get_logs('records', '', $options);
$mails = gosmtp_group_by($email_logs, array(), $multiselect);
$sent = $failed = $total = 0;
foreach($mails as $key =>$val){
$sent = $sent + $val['total']['sent'];
$failed = $failed + $val['total']['failed'];
$total = $total + $val['total']['total'];
}
echo'
"';
$email = '
GOSMTP Weekly Email Summary
 |
Hi there,
|
Let\'s take a look at how your emails performed over the last week.
|
✉
Total Emails
'.$total.'
▲'.gosmtp_cal_percentage($total, $total).'
✔
Sent
'.$sent.'
▲'.gosmtp_cal_percentage($sent, $total).'
✖
Failed
'.$failed.'
▼'.gosmtp_cal_percentage($failed, $total).'
|
Last Weeks Emails
|
View all Emails
|
|
';
if(!empty($mails)){
foreach($mails as $key => $val){
$email .= "".$val['total']['subject']." |
✉".$val['total']['total']."
✔".$val['total']['sent']."(".gosmtp_cal_percentage($val['total']['sent'], $val['total']['total']).")"."
✖".$val['total']['failed']."(".gosmtp_cal_percentage($val['total']['failed'], $val['total']['total']).")"."
|
";
// Print Only 5 Rows
if($key == 4){
break;
}
}
}else{
$email .="
Email Records were not found this week!
|
";
}
$email .=' |
';
if($send_email || isset($_GET['test_reports'])){
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
$admin_email = get_option('admin_email');
if(!empty($admin_email)){
$title = 'Weekly Report';
if(wp_mail($admin_email, $title, $email, $headers)){
echo '
'.__('Weekly email reports were sent from: '.$start.' to: '.$end.'').'
';
}else{
echo '
';
}
}else{
echo "";
}
}
// Update Timestamp
if($send_email){
$gosmtp->options['weekly_reports']['timestamp'] = strtotime("next ".$gosmtp->options['weekly_reports']['weekday']);
update_option( 'gosmtp_options', $gosmtp->options );
return;
}
$email.= '
';
echo $email;
}
?>