1. Go to this page and download the library: Download weezqyd/africastalking 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/ */
weezqyd / africastalking example snippets
use AfricasTalking\Gateway;
use Http\Adapter\BuzzAdapter;
// These Headers are ',
'Content-Type' => 'application/x-www-form-urlencoded',
];
$adapter = new BuzzAdapter($headers);
// Pass the adapter and your Africastalking Username to the gateway
// The third parameter is a sandbox flag when true the Api wiil run in the sandbox, The defaults is false
// Because we are using a custom client you dont need provide the API KEY to the gateway
// Instead pass an empty string or null
$gateway = new Gateway('USERNAME', null, true, $adapter);
use AfricasTalking\Gateway;
use Http\Exceptions\HttpException;
$gateway = new Gateway('API-TOKEN', 'USERNAME');
try {
$response = $gateway->sms->sendMessage('+254700123XXX', 'My sample message');
var_dump($response);
} catch(HttpException $e) {
print_r($e);
}