diff --git a/admin/email-log.php b/admin/email-log.php index 3968b86..dc7385e 100644 --- a/admin/email-log.php +++ b/admin/email-log.php @@ -217,16 +217,30 @@ $statusBadge = [ - 1): ?> -
- - 1): + $window = 2; + $pages = []; + 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); + ?> +
+ 1): ?> + + + - +
diff --git a/includes/email.php b/includes/email.php index 9bdbcf9..e85bb6d 100644 --- a/includes/email.php +++ b/includes/email.php @@ -57,12 +57,14 @@ class Email { } 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([ - 'from' => $this->fromEmail, + 'from' => $this->fromName . ' <' . $this->fromEmail . '>', 'to' => $to, 'subject' => $subject, 'html' => $html, - ], $options); + ], $apiOptions); if ($text) $payload['text'] = $text; $ch = curl_init('https://platform.cyberpersons.com/email/v1/send'); @@ -76,8 +78,16 @@ class Email { ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $curlErr = curl_error($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); if ($httpCode === 202) { $result = ['success' => true, 'message_id' => $body['data']['message_id'] ?? null]; diff --git a/includes/functions.php b/includes/functions.php index 68b277d..86019c4 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -336,7 +336,7 @@ function sendEmail($to, $subject, $htmlContent, $textContent = '') { error_log('[TJJ sendEmail] CYBERMAIL_API_KEY not configured'); 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; $ch = curl_init('https://platform.cyberpersons.com/email/v1/send'); curl_setopt_array($ch, [