PHP code example of sms77 / api

1. Go to this page and download the library: Download sms77/api 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/ */

    

sms77 / api example snippets



Seven\Api\Client;
use Seven\Api\Resource\Sms\SmsParams;
use Seven\Api\Resource\Sms\SmsResource;

// Initialize the client with your API key
$client = new Client('YOUR_API_KEY');

// Create SMS resource
$smsResource = new SmsResource($client);

// Send SMS
$response = $smsResource->dispatch(
    new SmsParams('Hello from seven.io!', '+491234567890')
);

echo "SMS sent successfully! ID: " . $response->getMessages()[0]->getId();

$params = (new SmsParams('Your message here', '+491234567890'))
    ->setFrom('YourBrand')
    ->setUnicode(true)
    ->setFlash(false);
    
$response = $smsResource->dispatch($params);

$params = new SmsParams(
    'Bulk message to multiple recipients',
    ['+491234567890', '+491234567891', '+491234567892']
);

$response = $smsResource->dispatch($params);

$params = (new SmsParams('Scheduled message', '+491234567890'))
    ->setDelay(new \DateTime('+1 hour'));
    
$response = $smsResource->dispatch($params);

use Seven\Api\Resource\Lookup\LookupResource;

$lookupResource = new LookupResource($client);
$result = $lookupResource->hlr('+491234567890');

echo "Carrier: " . $result->getCarrier();
echo "Country: " . $result->getCountry();

use Seven\Api\Resource\Balance\BalanceResource;

$balanceResource = new BalanceResource($client);
$balance = $balanceResource->get();

echo "Current balance: €" . $balance->getAmount();

use Seven\Api\Resource\Voice\VoiceResource;
use Seven\Api\Resource\Voice\VoiceParams;

$voiceResource = new VoiceResource($client);
$params = new VoiceParams('+491234567890', 'Hello, this is a test call');

$response = $voiceResource->call($params);

$client = new Client(
    apiKey: 'YOUR_API_KEY',
    signingSecret: 'YOUR_SIGNING_SECRET'
);

use Seven\Api\Exception\InvalidApiKeyException;
use Seven\Api\Exception\InsufficientBalanceException;

try {
    $response = $smsResource->dispatch($params);
} catch (InvalidApiKeyException $e) {
    echo "Invalid API key provided";
} catch (InsufficientBalanceException $e) {
    echo "Not enough balance to send SMS";
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}
bash
# Using production API key
SEVEN_API_KEY=your_api_key php vendor/bin/phpunit tests

# Using sandbox API key
SEVEN_API_KEY_SANDBOX=your_sandbox_key php vendor/bin/phpunit tests
bash
# Test only SMS functionality
php vendor/bin/phpunit tests/SmsTest.php

# Test with verbose output
php vendor/bin/phpunit tests --verbose