Ich ha
This commit is contained in:
@@ -57,26 +57,39 @@ final class Mailer
|
||||
'template' => $id,
|
||||
'placeholders' => $vars,
|
||||
];
|
||||
$payload['token'] = $apiToken;
|
||||
$payload['token'] = $apiToken;
|
||||
|
||||
$payloadForLog = $payload;
|
||||
$payloadForLog['token'] = '[hidden length ' . strlen((string)$apiToken) . ']';
|
||||
$this->log('template_api_request_payload', [
|
||||
'url' => $apiBase,
|
||||
'payload' => $payloadForLog,
|
||||
]);
|
||||
$payloadForLog = $payload;
|
||||
$payloadForLog['token'] = '[hidden length ' . strlen((string)$apiToken) . ']';
|
||||
$this->log('template_api_request_payload', [
|
||||
'url' => $apiBase,
|
||||
'payload' => $payloadForLog,
|
||||
]);
|
||||
|
||||
$this->log('template_api_request', ['template' => $id, 'placeholders' => array_keys($vars)]);
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => "Content-Type: application/json\r\n",
|
||||
$this->log('template_api_request', ['template' => $id, 'placeholders' => array_keys($vars)]);
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => "Content-Type: application/json\r\n",
|
||||
'timeout' => 15,
|
||||
'content' => json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
||||
],
|
||||
]);
|
||||
$resp = @file_get_contents($apiBase, false, $ctx);
|
||||
if ($resp !== false) {
|
||||
$status = null;
|
||||
if (isset($http_response_header) && is_array($http_response_header)) {
|
||||
foreach ($http_response_header as $hdr) {
|
||||
if (preg_match('~^HTTP/\\S+\\s+(\\d+)~i', $hdr, $m)) {
|
||||
$status = (int)$m[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->log('template_api_response_raw', [
|
||||
'status' => $status,
|
||||
'body' => $resp,
|
||||
]);
|
||||
$decoded = json_decode($resp, true);
|
||||
if (is_array($decoded) && !empty($decoded['ok']) && !empty($decoded['html'])) {
|
||||
$this->log('template_api_success', ['template' => $id, 'subject' => $decoded['subject'] ?? null, 'html_len' => strlen((string)$decoded['html'])]);
|
||||
|
||||
Reference in New Issue
Block a user