PHP code example of infobip / infobip-api-php-client
1. Go to this page and download the library: Download infobip/infobip-api-php-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
infobip / infobip-api-php-client example snippets
use Infobip\Configuration;
$configuration = new Configuration(
host: 'your-base-url',
apiKey: 'your-api-key'
);
use Infobip\ApiException;
use Infobip\Model\SmsRequest;
use Infobip\Model\SmsDestination;
use Infobip\Model\SmsMessage;
use Infobip\Api\SmsApi;
use Infobip\Model\SmsTextContent;
$sendSmsApi = new SmsApi(config: $configuration);
$message = new SmsMessage(
destinations: [
new SmsDestination(
to: '41793026727'
)
],
content: new SmsTextContent(
text: 'This is a dummy SMS message sent using infobip-api-php-client.'
),
sender: 'InfoSMS'
);
$request = new SmsRequest(messages: [$message]);
try {
$smsResponse = $sendSmsApi->sendSmsMessages($request);
} catch (ApiException $apiException) {
// HANDLE THE EXCEPTION
}
use Infobip\Model\SmsPreviewRequest;
$previewResponse = $sendSmsApi
->previewSmsMessage(
new SmsPreviewRequest(
text: 'Let\'s see how many characters will remain unused in this message.'
)
);
foreach ($previewResponse->getPreviews() ?? [] as $preview) {
echo sprintf(
'Characters remaining: %s, text preview: %s',
$preview->getCharactersRemaining(),
$preview->getTextPreview()
) . PHP_EOL;
}