$phoneE164, 'sender' => $sender, 'message' => str_replace('{code}', $code, $message), ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); if ($payload === false) { throw new RuntimeException('Unable to encode OTP request'); } $handle = curl_init($url); curl_setopt_array($handle, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload, CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Authorization: Bearer ' . $apiKey], CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 12, CURLOPT_PROTOCOLS => CURLPROTO_HTTPS, ]); $response = curl_exec($handle); $status = (int) curl_getinfo($handle, CURLINFO_RESPONSE_CODE); $error = curl_error($handle); curl_close($handle); if ($response === false || $status < 200 || $status >= 300) { error_log('OTP delivery failed; HTTP ' . $status . '; transport error: ' . $error); throw new RuntimeException('OTP provider rejected the request'); } } }