pass('administrator', true); } } catch (Exception $e) { $cnotIsAdmin = false; } catch (Throwable $e) { $cnotIsAdmin = false; } if (!$cnotIsAdmin) { include 'header.php'; include 'menu.php'; echo '
' . '
只有管理员可以查看邮件历史的发送记录。
'; include 'footer.php'; return; } /* ------------------------------------------------------------------ * 动作:预览邮件正文(GET,输出原始 HTML) * ------------------------------------------------------------------ */ if ($cnotAction === 'preview') { if (!MailNotifier_Plugin::checkMailLogToken($cnotGet('_'))) { while (ob_get_level() > 0) { ob_end_clean(); } header('Content-Type: text/plain; charset=UTF-8', true, 403); echo '链接已失效,请回到「邮件历史」页面重新打开。'; return; } $cnotRow = MailNotifier_MailLog::find(intval($cnotGet('id'))); while (ob_get_level() > 0) { ob_end_clean(); } header('Content-Type: text/html; charset=UTF-8'); if (!$cnotRow) { echo '
记录不存在或已被删除。
'; return; } $cnotBody = isset($cnotRow['body_text']) ? $cnotRow['body_text'] : ''; if (trim($cnotBody) === '') { echo '
这条记录没有保存邮件正文。
'; return; } echo $cnotBody; return; } /* ------------------------------------------------------------------ * 动作:备份 / 恢复 / 清空 / 删除(POST + 令牌) * ------------------------------------------------------------------ */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && $cnotAction !== '') { /* * 跳转必须走 Typecho 的 Response,不能只 header('Location:'): * 后台的响应是在 shutdown 阶段由 Response 统一发出的,它会用自己记的状态码 * (默认 200)盖掉我们设的 302,浏览器于是把「跳转」当成一个普通页面, * 刷新就会重复提交。Response::redirect() 会把状态码记成 302,才是对的。 */ $cnotResponse = (isset($response) && is_object($response) && method_exists($response, 'redirect')) ? $response : null; $cnotRedirect = function ($query) use ($cnotBase, $cnotResponse) { $url = $cnotBase . '&' . $query; if ($cnotResponse) { try { $cnotResponse->redirect($url); return $url; } catch (Exception $e) { } catch (Throwable $e) { } } header('Location: ' . $url, true, 302); return $url; }; if (!MailNotifier_Plugin::checkMailLogToken($cnotPost('_'))) { $cnotRedirect('msg=token'); exit; } if ($cnotAction === 'clear') { $cnotCount = MailNotifier_MailLog::clearAll(); $cnotRedirect('msg=clear_ok&n=' . intval($cnotCount)); exit; } if ($cnotAction === 'delete') { MailNotifier_MailLog::remove(intval($cnotPost('id'))); $cnotRedirect('msg=delete_ok'); exit; } /* 多选删除:ids 是逗号分隔的记录 id,由列表页的表单提交 */ if ($cnotAction === 'delete_multi') { $cnotIds = array(); foreach (explode(',', (string) $cnotPost('ids')) as $cnotId) { $cnotId = intval(trim($cnotId)); if ($cnotId > 0) { $cnotIds[] = $cnotId; } } $cnotCount = MailNotifier_MailLog::removeMany($cnotIds); $cnotRedirect('msg=delete_multi_ok&n=' . intval($cnotCount)); exit; } /* 重发:按记录里存的正文、当前的 SMTP 配置再发一次,结果记成新记录 */ if ($cnotAction === 'resend') { $cnotRow = MailNotifier_MailLog::find(intval($cnotPost('id'))); if (!$cnotRow) { $cnotRedirect('msg=resend_fail&detail=' . rawurlencode('记录不存在或已被删除')); exit; } $cnotResult = MailNotifier_Plugin::resendFromLog($cnotRow); if (!empty($cnotResult['ok'])) { $cnotRedirect('msg=resend_ok'); } else { $cnotRedirect('msg=resend_fail&detail=' . rawurlencode(MailNotifier_MailLog::cut( isset($cnotResult['message']) ? $cnotResult['message'] : '未知原因', 180 ))); } exit; } $cnotRedirect('msg=unknown'); exit; } /* ------------------------------------------------------------------ * 列表数据 * ------------------------------------------------------------------ */ $cnotFilters = array( 'status' => $cnotGet('status'), 'type' => $cnotGet('type'), 'keyword' => $cnotGet('keyword'), ); if ($cnotFilters['status'] !== 'ok' && $cnotFilters['status'] !== 'fail') { $cnotFilters['status'] = ''; } if (!array_key_exists($cnotFilters['type'], MailNotifier_MailLog::typeLabels())) { $cnotFilters['type'] = ''; } /* 每页条数:列表上可以临时切,没传参时用插件设置里存的默认值 */ $cnotPerPage = intval($cnotGet('per', (string) MailNotifier_Plugin::configRaw('mailPer', '20'))); $cnotPerOptions = array(20, 50, 100); if (!in_array($cnotPerPage, $cnotPerOptions, true)) { $cnotPerPage = 20; } $cnotPage = max(1, intval($cnotGet('page', '1'))); $cnotTableOk = MailNotifier_MailLog::ensureTable(); $cnotList = MailNotifier_MailLog::page($cnotFilters, $cnotPage, $cnotPerPage); $cnotStats = MailNotifier_MailLog::stats(); /* 分页 / 筛选链接 */ $cnotQuery = function ($overrides = array()) use ($cnotBase, $cnotFilters, $cnotPerPage) { $query = array( 'status' => $cnotFilters['status'], 'type' => $cnotFilters['type'], 'keyword' => $cnotFilters['keyword'], 'per' => $cnotPerPage, ); foreach ($overrides as $key => $value) { $query[$key] = $value; } $parts = array(); foreach ($query as $key => $value) { if ($value === '' || $value === null) { continue; } $parts[] = $key . '=' . rawurlencode((string) $value); } return $cnotBase . (empty($parts) ? '' : '&' . implode('&', $parts)); }; /* 顶部提示条 */ $cnotMsg = $cnotGet('msg'); $cnotNoticeCount = intval($cnotGet('n')); $cnotNotice = null; if ($cnotMsg === 'clear_ok') { $cnotNotice = array('ok', '已清空 ' . $cnotNoticeCount . ' 条发送记录。'); } elseif ($cnotMsg === 'delete_ok') { $cnotNotice = array('ok', '记录已删除。'); } elseif ($cnotMsg === 'delete_multi_ok') { $cnotNotice = array($cnotNoticeCount > 0 ? 'ok' : 'fail', $cnotNoticeCount > 0 ? '已删除 ' . $cnotNoticeCount . ' 条发送记录。' : '没有删掉任何记录,可能已被删除过。'); } elseif ($cnotMsg === 'resend_ok') { $cnotNotice = array('ok', '已重新发送,发送结果会作为新记录出现在列表顶部。'); } elseif ($cnotMsg === 'resend_fail') { $cnotNotice = array('fail', '重发失败:' . ($cnotGet('detail') !== '' ? $cnotGet('detail') : '未知原因')); } elseif ($cnotMsg === 'token') { $cnotNotice = array('fail', '安全令牌校验失败,请刷新页面后重试。'); } elseif ($cnotMsg === 'unknown') { $cnotNotice = array('fail', '无法识别的操作。'); } include 'header.php'; include 'menu.php'; ?>
发送记录表创建失败,记录暂时无法写入。请检查数据库账号是否有建表权限,或到 error_log 里搜 [MailNotifier] 看具体报错。
发送记录总数(最多保留 条)
发送成功
发送失败
发送记录 每封邮件发完就记一条,失败的也会记下来并写明原因
重置
已选 0 项
换个筛选条件试试。 等有人评论、或者点一次插件设置里的「测试发送」,这里就会出现记录。
状态 邮件 收件人 关联文章 邮件内容 发送时间 操作
成功 失败 — 查看 0 ? date('Y-m-d H:i', $cnotCreated) : '—'); ?>
1): ?> 1) { array_unshift($cnotPageList, 1, 0); } if ($cnotEnd < $cnotList['pages']) { $cnotPageList[] = 0; $cnotPageList[] = $cnotList['pages']; } } ?>
共 条 · 第 / 页 1): ?> 上一页 上一页 … 下一页 下一页
清空发送记录

只删记录,不影响插件设置和已发出的邮件。要备份设置,请到插件设置页顶部的「插件设置备份」。