1. Go to this page and download the library: Download nessworthy/textmarketer 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/ */
nessworthy / textmarketer example snippets
$apiCredentials = new \Nessworthy\TextMarketer\Authentication\Simple('api_username', 'api_password');
$httpClient = new \GuzzleHttp\Client();
$textMarketer = new \Nessworthy\TextMarketer\TextMarketer($apiCredentials, $httpClient);
$messageCommand = new \Nessworthy\TextMarketer\Message\SendMessage(
'This is a test message', // Your SMS Message.
['447777777777'], // The array of contact numbers.
'TestCompanyInc', // Who the message was sent from.
'testmessage', // Optional: Tag your message for delivery report filtering.
24, // Optional: Mark the message as time-sensitive: Should only be sent if it is within X hours.
true, // Optional: If true, if any recipient is matched in your STOP group the message will not be sent.
'[email protected]'// Optional: Your txtUS enterprise email (txtUS accounts only).
);
$deliveryResult = $textMarketer->sendMessage($messageCommand);
if ($deliveryResult->isSent()) {
echo 'Message sent with the ID of ' . $deliveryResult->getMessageId();
} elseif ($deliveryResult->isQueued()) {
echo 'Message queued with the ID of ' . $deliveryResult->getMessageId();
} elseif ($deliveryResult->isScheduled()) {
echo 'Is scheduled with the ID of ' . $deliveryResult->getScheduledId();
}
$scheduledDate = (new DateTimeImmutable)->modify('+1 month');
$deliveryResult = $textMarketer->sendScheduledMessage($messageCommand, $scheduledDate);
// Scheduled message ID can be found from the delivery result for scheduled messages:
// $scheduledMessageId = $deliveryResult->getScheduledId();
$textMarketer->deleteScheduledMessage($scheduledMessageId);
echo sprintf('I have %d remaining credits!', $textMarketer->getCreditCount());
$transferResult = $textMarketer->transferCreditsToAccountById(100, $someAccountId);
// Or by credentials:
$destinationCredentials = new \Nessworthy\TextMarketer\Authentication\Simple('username', 'password'));
$transferResult = $textMarketer->transferCreditsToAccountByCredentials(100, $destinationCredentials);
echo sprintf(
'I had %d credits. After transferring, I now have %d!',
$transferResult->getSourceCreditsBeforeTransfer(),
$transferResult->getSourceCreditsAfterTransfer()
);
echo '<br>';
echo sprintf(
'The target account had %d credits. After transferring, it now has %d!',
$transferResult->getTargetCreditsBeforeTransfer(),
$transferResult->getTargetCreditsAfterTransfer()
);
$groupCollection = $textMarketer->getGroupsList();
echo sprintf(
'I have %s groups!',
$groupCollection->isEmpty() ? 'no' : $groupCollection->getTotal()
);
echo '<br>';
echo 'Here is a summary of each group:';
foreach ($groupCollection->asArray() as $groupSummary) {
echo sprintf(
'Group name: %s (ID: %d) has %s numbers. It %s a stop group!',
$groupSummary->getName(),
$groupSummary->getId(),
$groupSummary->getNumberCount(),
$groupSummary->isStopGroup() ? 'IS' : 'IS NOT'
);
echo '<br/>';
}
$numbersToAdd = new Nessworthy\TextMarketer\Message\Part\PhoneNumberCollection([
'44700000000',
'44700000001',
'44700000002',
]);
$result = $textMarketer->addNumbersToGroup('MyGroupNameOrID', $numbersToAdd);
// Of the numbers - which ones were actually added to the list.
echo 'Added numbers: ' . $textMarketer->getTotalAddedNumbers();
echo 'Numbers added:<br>' . implode('<br>',$textMarketer->getAddedNumbers();
echo '<br>';
// Of the numbers - which ones were not added because they were on a STOP list.
echo 'Stopped numbers: ' . $textMarketer->getTotalStoppedNumbers();
echo 'Numbers added:<br>' . implode('<br>',$textMarketer->getStoppedNumbers();
echo '<br>';
// Of the numbers - which ones were not added because they were already on it.
echo 'Duplicated numbers: ' . $textMarketer->getTotalDuplicateNumbers();
echo 'Numbers added:<br>' . implode('<br>',$textMarketer->getDuplicateNumbers();
$group = $textMarketer->createGroup('mygroup');
echo sprintf(
'A new group was created by the name "%s" with an assigned ID of "%d"! The group %s a stop group.',
$group->getName(),
$group->getId(),
$group->isStopGroup() ? 'IS' : 'IS NOT'
);
// You can also use getNumberCount() and getNumbers(), which will return 0 and an empty array, respectively.
$group = $textMarketer->getGroupInformation('mygroup');
echo sprintf(
'The group is called "%s" with an assigned ID of "%d"! The group %s a stop group.',
$group->getName(),
$group->getId(),
$group->isStopGroup() ? 'IS' : 'IS NOT'
);
echo '<br/>';
echo sprintf(
'The group has %d numbers. Here they are:<br>%s',
$group->getNumberCount(),
implode('<br>', $group->getNumbers())
);
$reportCollection = $textMarketer->getDeliveryReportList();
echo sprintf(
'I have %s reports in total!',
$reportCollection->isEmpty() ? 'no' : $reportCollection->getTotal()
);
foreach ($reportCollection->asArray() as $report) {
echo '<br>';
echo sprintf(
'Report %s (last updated: %s) has extension %s.',
$report->getName(),
$report->getLastUpdated->format('d-m-Y H:i:s'),
$report->getExtension()
);
}
$newAccountDetails = new Nessworthy\TextMarketer\Account\UpdateAccountInformation(
'uiusername', // The new UI Username.
'uipassword', // The new UI Password.
'apiusername', // The new API Username.
'apipassword', // The new API Password.
'Company Name', // The new company name.
'[email protected]', // The new notification email address.
'447000000000', // The new notification mobile number.
);
$updatedAccountInformation = $textMarketer->updateAccountInformation($newAccountDetails);
$subAccount = new Nessworthy\TextMarketer\Account\CreateSubAccount(
'uiusername', // The new account's username
'uipassword', // Optional: The new account's password. If null is given, a random password will be generated.
'Company Name', // The new account's company name.
'[email protected]', // Optional: The new account's notification email address.
'447000000000', // Optional: The new account's notification mobile number.
false, // Whether to use the same pricing as the parent account.
'PROMOCODE' // Optional: A promo code for the account if you have one.
);
// All exceptions extend \Nessworthy\TextMarketer\TextMarketerException.
try {
// Send a text marketer request.
} catch (\Nessworthy\TextMarketer\Endpoint\EndpointException $e) {
// $e->getMessage() and $e->getCode() return the first message & message code.
// Or for all errors...
foreach ($e->getAllEndpointErrors() as $error) {
error_log(sprintf('TextMarketer Message Error: [%s] %s', $error->getCode(), $error->getMessage()));
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.