mirror of
https://github.com/myronblair/tomsjavajive
synced 2026-06-30 17:50:32 -05:00
Fix remaining code review findings: email transport errors, metadata payload, from-name, pagination
- Email::send(): add curl_error() check so transport failures (timeout, DNS, TLS) return a diagnosable error string instead of Unknown error - Email::send(): strip metadata key from options before array_merge so non-API fields are never sent to CyberMail endpoint - Email::send() + sendEmail(): include from-name in From field using RFC 5322 "Name <email>" format so fromName DB setting takes effect - email-log.php: replace unbounded page-link loop with a windowed paginator (first/last 2 pages + ±2 around current) with ellipsis gaps — prevents hundreds of anchors rendering at scale
This commit is contained in:
+19
-5
@@ -217,16 +217,30 @@ $statusBadge = [
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Pagination -->
|
<!-- Pagination -->
|
||||||
<?php if ($totalPages > 1): ?>
|
<?php if ($totalPages > 1):
|
||||||
<div style="display:flex;justify-content:center;gap:8px;margin-top:20px;">
|
$window = 2;
|
||||||
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
|
$pages = [];
|
||||||
<a href="?page=<?= $i ?>&search=<?= urlencode($search) ?>&status=<?= urlencode($statusFilter) ?>&customer=<?= urlencode($customerFilter) ?>"
|
for ($i = 1; $i <= $totalPages; $i++) {
|
||||||
|
if ($i <= $window || $i > $totalPages - $window || abs($i - $page) <= $window) {
|
||||||
|
$pages[] = $i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$pages = array_unique($pages);
|
||||||
|
sort($pages);
|
||||||
|
$qs = '&search=' . urlencode($search) . '&status=' . urlencode($statusFilter) . '&customer=' . urlencode($customerFilter);
|
||||||
|
?>
|
||||||
|
<div style="display:flex;justify-content:center;gap:8px;margin-top:20px;flex-wrap:wrap;">
|
||||||
|
<?php $prev = null; foreach ($pages as $i):
|
||||||
|
if ($prev !== null && $i - $prev > 1): ?>
|
||||||
|
<span style="padding:6px 4px;color:#9CA3AF;">…</span>
|
||||||
|
<?php endif; ?>
|
||||||
|
<a href="?page=<?= $i ?><?= $qs ?>"
|
||||||
style="padding:6px 12px;border-radius:4px;text-decoration:none;
|
style="padding:6px 12px;border-radius:4px;text-decoration:none;
|
||||||
background:<?= $i === $page ? '#FF5E1A' : '#f3f4f6' ?>;
|
background:<?= $i === $page ? '#FF5E1A' : '#f3f4f6' ?>;
|
||||||
color:<?= $i === $page ? 'white' : '#374151' ?>;">
|
color:<?= $i === $page ? 'white' : '#374151' ?>;">
|
||||||
<?= $i ?>
|
<?= $i ?>
|
||||||
</a>
|
</a>
|
||||||
<?php endfor; ?>
|
<?php $prev = $i; endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+12
-2
@@ -57,12 +57,14 @@ class Email {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function send(string $to, string $subject, string $html, ?string $text = null, array $options = []): array {
|
public function send(string $to, string $subject, string $html, ?string $text = null, array $options = []): array {
|
||||||
|
// Strip internal-only keys that are not CyberMail API fields
|
||||||
|
$apiOptions = array_diff_key($options, array_flip(['metadata']));
|
||||||
$payload = array_merge([
|
$payload = array_merge([
|
||||||
'from' => $this->fromEmail,
|
'from' => $this->fromName . ' <' . $this->fromEmail . '>',
|
||||||
'to' => $to,
|
'to' => $to,
|
||||||
'subject' => $subject,
|
'subject' => $subject,
|
||||||
'html' => $html,
|
'html' => $html,
|
||||||
], $options);
|
], $apiOptions);
|
||||||
if ($text) $payload['text'] = $text;
|
if ($text) $payload['text'] = $text;
|
||||||
|
|
||||||
$ch = curl_init('https://platform.cyberpersons.com/email/v1/send');
|
$ch = curl_init('https://platform.cyberpersons.com/email/v1/send');
|
||||||
@@ -76,8 +78,16 @@ class Email {
|
|||||||
]);
|
]);
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$curlErr = curl_error($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($curlErr) {
|
||||||
|
error_log('[TJJ Email] cURL error: ' . $curlErr);
|
||||||
|
$result = ['success' => false, 'error' => $curlErr, 'code' => 0];
|
||||||
|
$this->logEmail($to, $subject, $html, $result, $options);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
$body = json_decode($response, true);
|
$body = json_decode($response, true);
|
||||||
if ($httpCode === 202) {
|
if ($httpCode === 202) {
|
||||||
$result = ['success' => true, 'message_id' => $body['data']['message_id'] ?? null];
|
$result = ['success' => true, 'message_id' => $body['data']['message_id'] ?? null];
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ function sendEmail($to, $subject, $htmlContent, $textContent = '') {
|
|||||||
error_log('[TJJ sendEmail] CYBERMAIL_API_KEY not configured');
|
error_log('[TJJ sendEmail] CYBERMAIL_API_KEY not configured');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$payload = ['from' => $from, 'to' => $to, 'subject' => $subject, 'html' => $htmlContent];
|
$payload = ['from' => $fromName . ' <' . $from . '>', 'to' => $to, 'subject' => $subject, 'html' => $htmlContent];
|
||||||
if ($textContent) $payload['text'] = $textContent;
|
if ($textContent) $payload['text'] = $textContent;
|
||||||
$ch = curl_init('https://platform.cyberpersons.com/email/v1/send');
|
$ch = curl_init('https://platform.cyberpersons.com/email/v1/send');
|
||||||
curl_setopt_array($ch, [
|
curl_setopt_array($ch, [
|
||||||
|
|||||||
Reference in New Issue
Block a user