$number, "Body" => $message, ]; if (preg_match('/^[0-9+]+/', $from)) { $postData['From'] = $from; } else { $postData['MessagingServiceSid'] = $from; } curl_setopt_array($curl, [ CURLOPT_URL => 'https://api.twilio.com/2010-04-01/Accounts/' . urlencode($accountId) . '/Messages.json', CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postData, CURLOPT_USERNAME => $accountId, CURLOPT_PASSWORD => $apiToken, ]); $response = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); logNewMessage(LOG_DEBUG, 'SMS gateway response: ' . $response); $responseJson = json_decode($response, true); if ($httpCode !== 201) { logNewMessage(LOG_ERR, 'Unable to send SMS: ' . $response); $message = $responseJson['message'] ?? $responseJson['error_message'] ?? ''; throw new LAMException(null, $message); } } /** * @inheritDoc */ public function usesApiToken(): bool { return true; } /** * @inheritDoc */ public function usesApiKey(): bool { return false; } /** * @inheritDoc */ public function usesAccountId(): bool { return true; } /** * @inheritDoc */ public function usesFrom(): bool { return true; } /** * @inheritDoc */ public function usesRegion(): bool { return false; } /** * @inheritDoc */ public function usesSubject(): bool { return false; } }