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\SmsAdvancedTextualRequest;
use Infobip\Model\SmsDestination;
use Infobip\Model\SmsTextualMessage;
$sendSmsApi = new SmsApi(config: $configuration);
$message = new SmsTextualMessage(
destinations: [
new SmsDestination(to: '41793026727')
],
from: 'InfoSMS',
text: 'This is a dummy SMS message sent using infobip-api-php-client'
);
$request = new SmsAdvancedTextualRequest(messages: [$message]);
try {
$smsResponse = $sendSmsApi->sendSmsMessage($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;
}