PHP code example of track-any-device / sms-gateway

1. Go to this page and download the library: Download track-any-device/sms-gateway 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/ */

    

track-any-device / sms-gateway example snippets


use TrackAnyDevice\SmsGateway\Contracts\SmsGatewayContract;

class NotificationController extends Controller
{
    public function __construct(private SmsGatewayContract $sms) {}

    public function notify(string $phone): void
    {
        $this->sms->send($phone, 'Your order has been dispatched.');
    }
}

$sent = $sms->send('+447700900000', 'Hello from TAD!');

if (! $sent) {
    // false is returned on HTTP error, gateway error, or network exception
    // details are logged via Log::error
}

if ($sms->health()) {
    // gateway is reachable and reports status: ok
}

$messages = $sms->inbox();

// Each message:
// [
//     'index'   => '1',
//     'sender'  => '+447700900000',
//     'message' => 'Reply text',
//     'date'    => '2024/06/01 14:30:00+0100',
// ]

foreach ($messages as $msg) {
    $received = $sms->parseGatewayDate($msg['date']); // CarbonImmutable|null
    echo $msg['sender'].': '.$msg['message'];
}

$deleted = $sms->deleteMessage($msg['index']);

$status = $sms->status();

// Returns array or null:
// [
//     'signal'   => '-73 dBm',
//     'network'  => '4G',
//     'operator' => 'EE',
//     'sim'      => 'ready',
// ]

use TrackAnyDevice\SmsGateway\Contracts\SmsGatewayContract;

$this->mock(SmsGatewayContract::class)
    ->shouldReceive('send')
    ->once()
    ->with('+447700900000', 'Hello from TAD!')
    ->andReturn(true);
bash
php artisan vendor:publish --tag=sms-gateway-config