← Back
Editing: Logger.php
<?php namespace FluentMail\App\Models; use Exception; use InvalidArgumentException; use FluentMail\Includes\Support\Arr; use FluentMail\App\Services\Mailer\BaseHandler; class Logger extends Model { const STATUS_PENDING = 'pending'; const STATUS_FAILED = 'failed'; const STATUS_SENT = 'sent'; protected $fillables = [ 'to', 'from', 'subject', 'body', 'status', 'response', 'extra', 'created_at' ]; protected $searchables = [ 'to', 'from', 'subject' ]; /* * Columns log navigation may filter on. `filter_by` arrives from the * request and lands in the query as an identifier, which prepare() cannot * bind, so a value outside this list is dropped instead of interpolated. * Every key is re-checked against it in buildWhere()'s loop, which is the * one place an identifier is written into SQL. */ protected $filterables = [ 'status', 'created_at', 'to', 'from', 'subject' ]; protected $table = null; public function __construct() { parent::__construct(); $this->table = $this->db->prefix . FLUENT_MAIL_DB_PREFIX . 'email_logs'; } public function get($data) { $db = $this->getDb(); $page = isset($data['page']) ? (int)$data['page'] : 1; $perPage = isset($data['per_page']) ? (int)$data['per_page'] : 15; $offset = ($page - 1) * $perPage; $query = $db->table(FLUENT_MAIL_DB_PREFIX . 'email_logs') ->limit($perPage) ->offset($offset) ->orderBy('id', 'DESC'); if (!empty($data['status'])) { $query->where('status', sanitize_text_field($data['status'])); } if (!empty($data['date_range']) && is_array($data['date_range']) && count($data['date_range']) == 2) { $dateRange = $data['date_range']; $from = $dateRange[0] . ' 00:00:01'; $to = $dateRange[1] . ' 23:59:59'; $query->whereBetween('created_at', $from, $to); } if (!empty($data['search'])) { $search = trim(sanitize_text_field($data['search'])); $query->where(function ($q) use ($search) { $searchColumns = $this->searchables; $columnSearch = false; if (strpos($search, ':')) { $searchArray = explode(':', $search); $column = array_shift($searchArray); if (in_array($column, $this->fillables)) { $columnSearch = true; $q->where($column, 'LIKE', '%' . trim(implode(':', $searchArray)) . '%'); } } if (!$columnSearch) { $firstColumn = array_shift($searchColumns); $q->where($firstColumn, 'LIKE', '%' . $search . '%'); foreach ($searchColumns as $column) { $q->orWhere($column, 'LIKE', '%' . $search . '%'); } } }); } $result = $query->paginate(); $result['data'] = $this->formatResult($result['data']); return $result; } protected function buildWhere($data) { $where = []; $filterBy = Arr::get($data, 'filter_by'); if (isset($data['filter_by_value']) && in_array($filterBy, $this->filterables, true)) { $value = $this->normalizeFilterValue($filterBy, $data['filter_by_value']); if (!is_null($value)) { $where[$filterBy] = $value; } } /* * The date range travels beside filter_by rather than through it. * * There is only one filter_by slot and the logs screen already spends it on * status, so a viewer opened from a date-filtered list had no range at all and * its Prev/Next walked straight out of the result set the user was looking at. * Normalized through the same helper so the pair reaching the loop is scalar. */ $dateRange = $this->normalizeFilterValue('created_at', Arr::get($data, 'date_range')); if (!isset($where['created_at']) && is_array($dateRange)) { $where['created_at'] = $dateRange; } if (isset($data['query']) && is_scalar($data['query']) && trim($data['query']) !== '') { $query = trim($data['query']); $columns = $this->searchables; /* * The same reading get() gives the search box: `subject:invoice` is a * search of that one column, not of every column for the literal text. * The viewer's Prev and Next walk the list the search produced, so a * column search that the list understood and the navigation did not * left Next with nothing to land on. */ if (strpos($query, ':')) { $parts = explode(':', $query); $column = array_shift($parts); if (in_array($column, $this->filterables, true)) { $columns = [$column]; $query = trim(implode(':', $parts)); } } foreach ($columns as $column) { if (isset($where[$column])) { $where[$column] .= '|' . $query; } else { $where[$column] = $query; } } } $args = [1]; $andWhere = $orWhere = ''; $whereClause = "WHERE 1 = '%d'"; foreach ($where as $key => $value) { if (!in_array($key, $this->filterables, true)) { continue; } if (in_array($key, ['status', 'created_at'])) { if ($key == 'created_at') { if (is_array($value)) { $args[] = $value[0]; $args[] = $value[1]; } else { $args[] = $value; $args[] = $value; } $andWhere .= " AND `{$key}` >= '%s' AND `{$key}` < '%s' + INTERVAL 1 DAY"; } else { $args[] = $value; $andWhere .= " AND `{$key}` = '%s'"; } } else { if (strpos($value, '|')) { $nestedOr = ''; $values = explode('|', $value); foreach ($values as $itemValue) { $args[] = '%' . $this->db->esc_like($itemValue) . '%'; $nestedOr .= " OR `{$key}` LIKE '%s'"; } $orWhere .= ' OR (' . trim($nestedOr, 'OR ') . ')'; } else { $args[] = '%' . $this->db->esc_like($value) . '%'; $orWhere .= " OR `{$key}` LIKE '%s'"; } } } if ($orWhere) { $orWhere = 'AND (' . trim($orWhere, 'OR ') . ')'; } $whereClause = implode(' ', [$whereClause, trim($andWhere), $orWhere]); return [$whereClause, $args]; } /** * `created_at` is the one filter carried as a [from, to] pair; every other * column takes a single value. The request can send either as an array, so * anything that would reach the string operations in buildWhere() as a * non-scalar is normalized here or dropped. Returns null when there is * nothing usable left. */ protected function normalizeFilterValue($column, $value) { if (is_scalar($value)) { return $value; } if ($column != 'created_at' || !is_array($value)) { return null; } $value = array_values(array_filter($value, 'is_scalar')); if (count($value) > 1) { return [$value[0], $value[1]]; } return count($value) ? $value[0] : null; } protected function formatResult($result) { $result = is_array($result) ? $result : func_get_args(); foreach ($result as $key => $row) { $result[$key] = $this->maybeUnserialize((array)$row); $result[$key]['id'] = (int)$result[$key]['id']; $result[$key]['retries'] = (int)$result[$key]['retries']; $result[$key]['from'] = htmlspecialchars($result[$key]['from']); /* * No wp_kses_post() here. Both consumers render the subject as text * — {{ }} in Logs.vue and LogViewer.vue, which escapes on its own — * so kses adds no safety, and its entity normalization rewrites a * subject reading "Tom & Jerry" to "Tom & Jerry", which the * page then shows verbatim. Anything that puts a subject into * HTML has to escape it at that point, as digest_email.php does. */ $result[$key]['subject'] = wp_unslash($result[$key]['subject']); if (array_key_exists('attachments', $result[$key])) { $result[$key]['attachment_list'] = static::describeAttachments($result[$key]['attachments']); $result[$key]['attachments'] = BaseHandler::attachmentsForLog($result[$key]['attachments']); } } return $result; } /** * Each logged attachment with whether a resend can include it. * * - `ok`: a file that is still readable where it was attached from. * - `in_memory`: data the sending plugin built in memory (addStringAttachment(), * e.g. an invoice PDF). The log does not keep the data, so it cannot be resent. * - `missing`: a file that has been deleted, moved or can no longer be read. * - `unchecked`: a file whose state was not looked up ($checkFiles false). * * The log list and viewer do not check files: that is a few filesystem calls * per attachment on every page load, slow on network storage, for a state * that only matters when a resend is about to run. The resend actions ask * for it through attachmentStatus() instead. * * @param mixed $attachments The unserialized `attachments` column. * @param bool $checkFiles Look up whether each file can still be read. * @return array[] [['name' => string, 'status' => string, 'inline' => bool, 'size' => int|null], ...] */ public static function describeAttachments($attachments, $checkFiles = false) { if (!is_array($attachments)) { return []; } $list = []; foreach ($attachments as $attachment) { $described = static::describeAttachment($attachment, $checkFiles); if ($described) { unset($described['record']); $list[] = $described; } } return $list; } /** * One logged attachment, normalized: its PHPMailer record and how it stands. * * @param mixed $attachment A PHPMailer record, or a bare path from very old rows. * @param bool $checkFiles Look up whether a file can still be read; otherwise its status is `unchecked`. * @return array|null ['name', 'status', 'inline', 'size', 'record'], or null when the entry is not an attachment. */ protected static function describeAttachment($attachment, $checkFiles = true) { if (is_string($attachment) && $attachment !== '') { $attachment = [$attachment, basename($attachment), basename($attachment)]; } if (!is_array($attachment)) { return null; } $inMemory = !empty($attachment[5]); $path = isset($attachment[0]) && is_string($attachment[0]) ? $attachment[0] : ''; $readable = !$inMemory && $checkFiles && BaseHandler::isReadableAttachmentPath($path); if ($inMemory) { $size = isset($attachment[8]) ? (int) $attachment[8] : (is_string($path) ? strlen($path) : null); $status = 'in_memory'; } else { $size = $readable ? (int) @filesize($path) : null; $status = !$checkFiles ? 'unchecked' : ($readable ? 'ok' : 'missing'); } return [ 'name' => (string) BaseHandler::attachmentName($attachment), 'status' => $status, 'inline' => isset($attachment[6]) && $attachment[6] === 'inline', 'size' => $size, 'record' => $attachment, ]; } protected function maybeUnserialize(array $data) { foreach ($data as $key => $value) { if ($this->isUnserializable($key)) { $data[$key] = $this->unserialize($value); } } if (array_key_exists('to', $data)) { $data['to'] = $this->normalizeLoggedRecipients($data['to']); } return $data; } protected function isUnserializable($key) { $allowedFields = [ 'to', 'headers', 'attachments', 'response', 'extra' ]; return in_array($key, $allowedFields); } protected function unserialize($data) { if (is_serialized($data)) { if (preg_match('/(^|;)O:[0-9]+:/', $data)) { return $data; } return unserialize(trim($data), ['allowed_classes' => false]); } return $data; } /** * Turn a stored `to` value into the `[{email, name?}, ...]` shape the log * UI and resend path expect. * * Rows written while `to` was VARCHAR(255) can hold a clipped serialize * blob that `is_serialized()` rejects. Pull complete addresses out of * that fragment so the viewer does not print `a:7:{i:0;a:1:{s:5:"email"` * and resend does not foreach a string. A trailing half-written address * is dropped because it is not a valid mailbox. * * @param mixed $to * @return array|mixed */ protected function normalizeLoggedRecipients($to) { if (is_array($to)) { return $to; } if (!is_string($to) || $to === '') { return $to; } $recipients = []; if (strpos(ltrim($to), 'a:') === 0) { if (preg_match_all('/s:\d+:"([^"]+)"/', $to, $matches)) { foreach ($matches[1] as $value) { if (is_email($value)) { $recipients[] = ['email' => $value]; } } } return $recipients; } foreach (preg_split('/[\s,;]+/', $to) as $address) { $address = trim($address, " \t\n\r\0\x0B<>"); if (is_email($address)) { $recipients[] = ['email' => $address]; } } return $recipients ?: $to; } protected function formatHeaders($headers) { foreach ((array)$headers as $key => $header) { if (is_array($header)) { $header = $this->formatHeaders($header); } else { $header = htmlspecialchars($header); } $headers[$key] = $header; } return $headers; } public function add($data) { try { $data = array_merge($data, [ 'created_at' => current_time('mysql') ]); return $this->getDb()->table(FLUENT_MAIL_DB_PREFIX . 'email_logs') ->insert($data); } catch (Exception $e) { return $e; } } public function delete(array $id) { if ($id && $id[0] == 'all') { // TRUNCATE doesn't support parameterization // Table name is safe - constructed from constants in __construct() $result = $this->db->query("TRUNCATE TABLE {$this->table}"); // The table is empty now, so widening an old VARCHAR `to` column is instant. if ($result !== false) { require_once FLUENTMAIL_PLUGIN_PATH . 'database/migrations/EmailLogs.php'; \FluentMailMigrations\EmailLogs::maybeWidenToColumn($this->table); } return $result; } $ids = array_filter($id, 'intval'); if ($ids) { return $this->getDb()->table(FLUENT_MAIL_DB_PREFIX . 'email_logs') ->whereIn('id', $ids) ->delete(); } return false; } public function navigate($data) { $filterBy = Arr::get($data, 'filter_by'); foreach (['date', 'daterange', 'datetime', 'datetimerange'] as $field) { if ($filterBy == $field) { $data['filter_by'] = 'created_at'; } } /* * The cursor is bound as '%d', so it cannot carry SQL either way, but * an array-shaped `id` from the request reaches prepare() as an * unsupported argument type and trips _doing_it_wrong(), which prints * a notice into the AJAX response body on a debug site. Narrowed to an * integer here instead. */ $id = isset($data['id']) && is_scalar($data['id']) ? (int) $data['id'] : 0; $dir = isset($data['dir']) ? $data['dir'] : null; list($where, $args) = $this->buildWhere($data); $args = array_merge($args, [$id]); $sqlNext = "SELECT * FROM {$this->table} {$where} AND `id` > '%d' ORDER BY id LIMIT 2"; $sqlPrev = "SELECT * FROM {$this->table} {$where} AND `id` < '%d' ORDER BY id DESC LIMIT 2"; if ($dir == 'next') { $query = $this->db->prepare($sqlNext, $args); } else if ($dir == 'prev') { $query = $this->db->prepare($sqlPrev, $args); } else { foreach (['next' => $sqlNext, 'prev' => $sqlPrev] as $key => $sql) { $keyResult = $this->db->get_results( $this->db->prepare($sql, $args) ); $result[$key] = $this->formatResult($keyResult); } return $result; } $result = $this->db->get_results($query); if (count($result) > 1) { $next = true; $prev = true; } else { if ($dir == 'next') { $next = false; $prev = true; } else { $next = true; $prev = false; } } return [ 'log' => $result ? $this->formatResult($result[0])[0] : null, 'next' => $next, 'prev' => $prev ]; } /** * Whether a resend of each log can still include its attachments. * * Called by the resend actions just before they run, for the logs that have * attachments, so the log list itself never touches the filesystem. * * @param int[] $ids At most 50 log ids; the rest are ignored. * @return array Log id => describeAttachments() list, with files checked. */ public function attachmentStatus(array $ids) { $ids = array_slice(array_values(array_unique(array_filter(array_map('intval', $ids)))), 0, 50); if (!$ids) { return []; } $placeholders = implode(',', array_fill(0, count($ids), '%d')); $rows = $this->db->get_results($this->db->prepare( "SELECT `id`, `attachments` FROM {$this->table} WHERE `id` IN ({$placeholders})", $ids )); $statuses = []; foreach ((array) $rows as $row) { $statuses[(int) $row->id] = static::describeAttachments($this->unserialize($row->attachments), true); } return $statuses; } public function find($id) { $row = $this->getDb()->table(FLUENT_MAIL_DB_PREFIX . 'email_logs') ->where('id', $id) ->first(); $row->extra = $this->unserialize($row->extra); $row->response = $this->unserialize($row->response); return (array)$row; } public function resendEmailFromLog($id, $type = 'retry', $recipients = []) { $email = $this->find($id); $email['to'] = $this->normalizeLoggedRecipients($this->unserialize($email['to'])); $email['headers'] = $this->unserialize($email['headers']); $email['attachments'] = $this->unserialize($email['attachments']); $email['extra'] = $this->unserialize($email['extra']); /* * Files still on disk go out again under their original name, and inline * images with their original cid, through wp_mail()'s own arguments: an * attachment keyed by its file name, and embeds keyed by cid. No hook is * needed, so filters, pre_wp_mail transports and queue plugins see the * same files the resend sends. In-memory attachments and files that are * gone cannot be included; they are reported back so the admin is told. */ $skippedAttachments = []; $wpMailAttachments = []; $wpMailEmbeds = []; $embedMeta = []; // Another plugin's wp_mail() may not take $embeds (the sixth argument). Inline // images then go out as ordinary attachments rather than being dropped. $acceptsEmbeds = true; try { $wpMail = new \ReflectionFunction('wp_mail'); // A variadic wrapper (wp_mail(...$args)) forwards whatever it is given. $acceptsEmbeds = $wpMail->isVariadic() || $wpMail->getNumberOfParameters() >= 6; } catch (\ReflectionException $e) { $acceptsEmbeds = true; } foreach ((is_array($email['attachments']) ? $email['attachments'] : []) as $attachment) { $described = static::describeAttachment($attachment); if (!$described) { continue; } if ($described['status'] !== 'ok') { $skippedAttachments[] = ['name' => $described['name'], 'status' => $described['status']]; continue; } $path = $described['record'][0]; $cid = isset($described['record'][7]) ? (string) $described['record'][7] : ''; if ($acceptsEmbeds && $described['inline'] && $cid !== '' && !isset($wpMailEmbeds[$cid])) { $wpMailEmbeds[$cid] = $path; $embedMeta[$cid] = [ 'path' => $path, 'name' => $described['name'], 'type' => isset($described['record'][4]) ? (string) $described['record'][4] : '', ]; continue; } // A name that is already used, or one PHP would turn into an integer key, // cannot be a key; that file goes out under its own file name instead. $name = $described['name']; if ($name === '' || isset($wpMailAttachments[$name]) || (string) (int) $name === $name) { $wpMailAttachments[] = $path; } else { $wpMailAttachments[$name] = $path; } } // When custom recipients are provided, drop cc/bcc headers so the email // is only delivered to the requested address(es). $hasCustomRecipients = !empty($recipients) && is_array($recipients); $skipHeaderKeys = $hasCustomRecipients ? ['cc', 'bcc'] : []; $headers = []; foreach ($email['headers'] as $key => $value) { if (in_array(strtolower((string) $key), $skipHeaderKeys, true)) { continue; } if($key == 'content-type' && $value == 'multipart/alternative') { $value = 'text/html'; } if (is_array($value)) { $values = []; $value = array_filter($value); foreach ($value as $v) { if (is_array($v) && isset($v['email'])) { $v = $v['email']; } $values[] = $v; } if ($values) { // wp_mail() splits Cc, Bcc and Reply-To on commas only; any // other separator turns the list into one invalid address, // which is silently dropped. $headers[] = "{$key}: " . implode(', ', $values); } } else { if ($value) { $headers[] = "{$key}: $value"; } } } $headers = array_merge($headers, [ 'From: ' . $email['from'] ]); if ($hasCustomRecipients) { $to = array_values($recipients); } else { $to = []; foreach ((array)$email['to'] as $recipient) { if (!is_array($recipient)) { if (is_string($recipient) && is_email($recipient)) { $to[] = $recipient; } continue; } if (empty($recipient['email'])) { continue; } if (!empty($recipient['name'])) { $to[] = $recipient['name'] . ' <' . $recipient['email'] . '>'; } else { $to[] = $recipient['email']; } } } try { if (!defined('FLUENTMAIL_LOG_OFF')) { define('FLUENTMAIL_LOG_OFF', true); } $startedAt = microtime(true); // wp_mail() names an embed after its path and detects its type; give the // resend's own embeds (same path and cid) their logged name and type. $embedArgs = function ($args) use ($embedMeta) { $cid = isset($args['cid']) ? (string) $args['cid'] : ''; if (isset($embedMeta[$cid]) && isset($args['path']) && $args['path'] === $embedMeta[$cid]['path']) { $args['name'] = $embedMeta[$cid]['name']; if ($embedMeta[$cid]['type'] !== '') { $args['type'] = $embedMeta[$cid]['type']; } } return $args; }; add_filter('wp_mail_embed_args', $embedArgs); try { $result = wp_mail( $to, $email['subject'], $email['body'], $headers, $wpMailAttachments, $wpMailEmbeds ); } finally { remove_filter('wp_mail_embed_args', $embedArgs); } $durationMs = round((microtime(true) - $startedAt) * 1000, 1); $updateData = [ 'status' => 'sent', 'updated_at' => current_time('mysql'), ]; if (!$result && $type == 'check_realtime' && $email['status'] == 'failed') { $updateData['status'] = 'failed'; } if ($type == 'resend') { $updateData['resent_count'] = intval($email['resent_count']) + 1; $updateData['extra'] = maybe_serialize( $this->appendResendRecord($email['extra'], $to, (bool)$result, $durationMs) ); } else { $updateData['retries'] = intval($email['retries']) + 1; } if ($this->updateLog($updateData, ['id' => $id])) { $email = $this->find($id); $email['to'] = $this->normalizeLoggedRecipients($this->unserialize($email['to'])); $email['headers'] = $this->unserialize($email['headers']); $email['attachments'] = $this->unserialize($email['attachments']); $email['extra'] = $this->unserialize($email['extra']); $email['attachment_list'] = static::describeAttachments($email['attachments']); $email['attachments'] = BaseHandler::attachmentsForLog($email['attachments']); $email['skipped_attachments'] = $skippedAttachments; $email['resend_succeeded'] = (bool) $result; return $email; } } catch (\PHPMailer\PHPMailer\Exception $e) { throw $e; } } /** * Record where a resend actually went. * * A resend can now be redirected to an address other than the original * recipient, and resent_count alone only says that it happened, not where * it landed - so a log row could show three resends with nothing to say * that two of them went to somebody else entirely. The trail lives in the * existing `extra` column, which needs no schema change, and the row's own * `to` stays untouched as the record of the original send. * * @param mixed $extra The unserialized `extra` column. * @param array $to Recipients this resend was addressed to. * @param bool $sent Whether the send itself reported success. * @param float $ms How long the send took, in milliseconds. * @return array */ protected function appendResendRecord($extra, $to, $sent, $ms = null) { $extra = is_array($extra) ? $extra : []; $resends = []; if (!empty($extra['resends']) && is_array($extra['resends'])) { $resends = $extra['resends']; } $user = wp_get_current_user(); $resends[] = [ 'at' => current_time('mysql'), 'to' => array_values(array_map('strval', (array)$to)), // The display name as it stood at the time. Storing an ID would // leave the trail unreadable once the account is deleted, which is // exactly when it matters. 'by' => ($user && $user->exists()) ? $user->display_name : '', 'sent' => $sent, 'ms' => $ms ]; // Keep the tail. A row that gets resent all day should not grow its // extra column without bound. $limit = apply_filters('fluentsmtp_resend_history_limit', 20); if (count($resends) > $limit) { $resends = array_slice($resends, -$limit); } $extra['resends'] = array_values($resends); return $extra; } public function updateLog($data, $where) { return $this->db->update($this->table, $data, $where); } public function getStats() { // Status values are hardcoded, no need for prepare() $succeeded = $this->db->get_var("SELECT COUNT(id) FROM {$this->table} WHERE status = 'sent'"); $failed = $this->db->get_var("SELECT COUNT(id) FROM {$this->table} WHERE status = 'failed'"); return [ 'sent' => $succeeded, 'failed' => $failed ]; } public function deleteLogsOlderThan($days) { try { $date = gmdate('Y-m-d H:i:s', current_time('timestamp') - $days * DAY_IN_SECONDS); /* * Deleted in batches rather than in one statement. A site that has * been logging for months can have this cron pass hit hundreds of * thousands of rows, and a single unbounded DELETE holds locks for * the whole scan - long enough to time out and leave the backlog * permanently uncleared, since the next run faces the same pile. * Batches let each statement commit and release. */ $batchSize = (int)apply_filters('fluentmail_log_delete_batch_size', 2000); $batchSize = max(1, $batchSize); $deleted = 0; do { $query = $this->db->prepare( "DELETE FROM {$this->table} WHERE `created_at` < %s LIMIT %d", $date, $batchSize ); $result = $this->db->query($query); if (!$result) { break; } $deleted += $result; } while ($result >= $batchSize); return $deleted; } catch (Exception $e) { fluentMailDebugLog('Failed to delete old email logs - ' . $e->getMessage()); } } public function getTotalCountStat($status, $startDate, $endDate = false) { if ($endDate) { $query = $this->db->prepare( "SELECT COUNT(*) FROM {$this->table} WHERE status = %s AND created_at >= %s AND created_at <= %s", $status, $startDate, $endDate ); } else { $query = $this->db->prepare( "SELECT COUNT(*) FROM {$this->table} WHERE status = %s AND created_at >= %s", $status, $startDate ); } return (int)$this->db->get_var($query); } public function getSubjectCountStat($status, $startDate, $endDate) { $query = $this->db->prepare( "SELECT COUNT(DISTINCT(subject)) FROM {$this->table} WHERE status = %s AND created_at >= %s AND created_at <= %s", $status, $startDate, $endDate ); return (int)$this->db->get_var($query); } public function getSubjectStat($status, $statDate, $endDate, $limit = 5) { // Sanitize and validate limit as positive integer $limit = max(1, absint($limit)) ?: 5; $query = $this->db->prepare( "SELECT subject, COUNT(DISTINCT id) AS emails_sent FROM {$this->table} WHERE created_at >= %s AND created_at <= %s AND status = %s GROUP BY subject ORDER BY emails_sent DESC LIMIT %d", $statDate, $endDate, $status, $limit ); return $this->db->get_results($query, ARRAY_A); } }
Save File
Cancel