1. Go to this page and download the library: Download netgsm/sms 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/ */
netgsm / sms example snippets
use Netgsm\Sms\NetgsmClient;
use Netgsm\Sms\NetgsmException;
$client = new NetgsmClient(getenv('NETGSM_USERNAME'), getenv('NETGSM_PASSWORD'));
try {
$result = $client->send(getenv('NETGSM_SENDER'), [
['recipient' => '+905321234567', 'text' => 'Siparişiniz kargoya verildi.'],
['recipient' => '+905321234568', 'text' => 'Siparişiniz hazırlanıyor.'],
], ['encoding' => 'TURKISH']);
// $result['jobId'] ile rapor sorgulanır.
foreach ($result['rejectedItems'] as $item) {
// Geçerli kayıtlar gönderildi; bu kayıt reddedildi.
error_log("Reddedildi: {$item['recipient']} {$item['reason']}");
}
} catch (NetgsmException $e) {
error_log($e->getMessage()); // requestId içerir
}
$client = new NetgsmClient($username, $password, $cache); // Psr\SimpleCache\CacheInterface
use Illuminate\Support\Facades\Cache;
use Netgsm\Sms\NetgsmClient;
public function register(): void
{
$this->app->singleton(NetgsmClient::class, fn () => new NetgsmClient(
env('NETGSM_USERNAME'),
env('NETGSM_PASSWORD'),
Cache::store(),
));
}
$tz = new DateTimeZone('Europe/Istanbul');
$page = $client->report([$jobId], new DateTimeImmutable('today', $tz), new DateTimeImmutable('now', $tz));
$inbox = $client->inbox(new DateTimeImmutable('-1 day'), new DateTimeImmutable());
$client->blacklist(); // liste, sayfa 0, sayfa başına 200
$client->blacklist(['+905321234567']); // numara listede mi
$client->addToBlacklist(['+905321234567']);
$client->removeFromBlacklist(['+905321234567']);
$balance = $client->balance(3);
try {
$client->send($sender, $messages);
} catch (NetgsmException $e) {
if ($e->mayHaveBeenQueued) {
// Gönderim oluşmuş olabilir. Aynı isteği tekrar göndermek ikinci bir gönderim oluşturur;
// önce report() ile kontrol edin.
} elseif ($e->errorCode === 'RATE_LIMITED' && $e->retryAfter !== null) {
// $e->retryAfter saniye sonra tekrar deneyin.
} elseif ($e->errorCode === 'RATE_LIMITED') {
// Retry-After yok: hesabın gönderimi askıya alınmış. Beklemek işe yaramaz, destek ekibine başvurun.
} else {
// 400, 403, 422: istek ya da hesap düzeltilmeden tekrar denemeyin.
}
}
use Netgsm\Sms\Http\CurlTransport;
$client = new NetgsmClient($username, $password, $cache, NetgsmClient::BASE_URL, new CurlTransport(caBundle: '/etc/ssl/cacert.pem'));
$client = new NetgsmClient('8500000000', '<sandbox şifresi>', null, 'https://ext-sandbox.netgsm.com.tr');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.