Ich ha
This commit is contained in:
@@ -57,26 +57,39 @@ final class Mailer
|
|||||||
'template' => $id,
|
'template' => $id,
|
||||||
'placeholders' => $vars,
|
'placeholders' => $vars,
|
||||||
];
|
];
|
||||||
$payload['token'] = $apiToken;
|
$payload['token'] = $apiToken;
|
||||||
|
|
||||||
$payloadForLog = $payload;
|
$payloadForLog = $payload;
|
||||||
$payloadForLog['token'] = '[hidden length ' . strlen((string)$apiToken) . ']';
|
$payloadForLog['token'] = '[hidden length ' . strlen((string)$apiToken) . ']';
|
||||||
$this->log('template_api_request_payload', [
|
$this->log('template_api_request_payload', [
|
||||||
'url' => $apiBase,
|
'url' => $apiBase,
|
||||||
'payload' => $payloadForLog,
|
'payload' => $payloadForLog,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->log('template_api_request', ['template' => $id, 'placeholders' => array_keys($vars)]);
|
$this->log('template_api_request', ['template' => $id, 'placeholders' => array_keys($vars)]);
|
||||||
$ctx = stream_context_create([
|
$ctx = stream_context_create([
|
||||||
'http' => [
|
'http' => [
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'header' => "Content-Type: application/json\r\n",
|
'header' => "Content-Type: application/json\r\n",
|
||||||
'timeout' => 15,
|
'timeout' => 15,
|
||||||
'content' => json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
'content' => json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$resp = @file_get_contents($apiBase, false, $ctx);
|
$resp = @file_get_contents($apiBase, false, $ctx);
|
||||||
if ($resp !== false) {
|
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);
|
$decoded = json_decode($resp, true);
|
||||||
if (is_array($decoded) && !empty($decoded['ok']) && !empty($decoded['html'])) {
|
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'])]);
|
$this->log('template_api_success', ['template' => $id, 'subject' => $decoded['subject'] ?? null, 'html_len' => strlen((string)$decoded['html'])]);
|
||||||
|
|||||||
Reference in New Issue
Block a user