PHP code example of serwersms / serwersmsbundle

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

    

serwersms / serwersmsbundle example snippets


namespace App\Controller;

use SerwerSMS\SerwerSMSBundle\SerwerSMSInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;

class SmsController extends AbstractController
{
    public function __construct(private SerwerSMSInterface $serwerSms)
    {
    }

    #[Route('/send-sms')]
    public function sendSms(): JsonResponse
    {
        try {

            $result = $this->serwerSms->messages()->sendSms(
                [
                    '+48500600700',
                    '+48600700800'
                 ],
                'Test FULL message',
                'INFORMACJA',
                [
                    'test' => true,
                    'details' => true
                ]
            );

            return new JsonResponse($result);

        } catch (\Exception $e) {
            return new JsonResponse(['error' => $e->getMessage()], 500);
        }
    }
}

try {

    // SMS FULL
    $result = $this->serwerSms->messages()->sendSms(
        [
            '+48500600700',
            '+48600700800'
        ],
        'Test FULL message',
        'INFORMACJA',
        [
            'test' => true,
            'details' => true
        ]
    );

    // SMS ECO
    $result = $this->serwerSms->messages()->sendSms(
        [
            '+48500600700',
            '+48600700800'
        ],
        'Test ECO message',
        null,
        [
            'test' => true,
            'details' => true
        ]
    );

    // VOICE from text
    $result = $this->serwerSms->messages()->sendVoice(
        [
            '+48500600700',
            '+48600700800'
        ],
        [
            'text' => 'Test message',
            'test' => true,
            'details' => true
        ]
    );

    // MMS
    $list = $this->serwerSms->files()->index('mms');
    $result = $this->serwerSms->messages()->sendMms(
        [
            '+48500600700',
            '+48600700800'
        ],
        'MMS Title',
        [
            'test' => true,
            'file_id' => $list->items[0]->id,
            'details' => true
        ]
    );

    echo 'Skolejkowano: ' . $result->queued . '<br />';
    echo 'Niewysłano: ' . $result->unsent . '<br />';

    foreach ($result->items as $sms) {
        echo 'ID: ' . $sms->id . '<br />';
        echo 'NUMER: ' . $sms->phone . '<br />';
        echo 'STATUS: ' . $sms->status . '<br />';
        echo 'CZĘŚCI: ' . $sms->parts . '<br />';
        echo 'WIADOMOŚĆ: ' . $sms->text . '<br />';
    }

} catch (\Exception $e) {
    echo 'ERROR: ' . $e->getMessage();
}

try {

    $messages[] = [
        'phone' => '500600700',
        'text' => 'First message'
    ];
    $messages[] = [
        'phone' => '600700800',
        'text' => 'Second message'
    ];

    $result = $this->serwerSms->messages()->sendPersonalized(
        $messages,
        'INFORMACJA',
        [
            'test' => true,
            'details' => true
        ]
    );

    echo 'Skolejkowano: ' . $result->queued . '<br />';
    echo 'Niewysłano: ' . $result->unsent . '<br />';

    foreach ($result->items as $sms) {
        echo 'ID: ' . $sms->id . '<br />';
        echo 'NUMER: ' . $sms->phone . '<br />';
        echo 'STATUS: ' . $sms->status . '<br />';
        echo 'CZĘŚCI: ' . $sms->parts . '<br />';
        echo 'WIADOMOŚĆ: ' . $sms->text . '<br />';
    }

} catch (\Exception $e) {
    echo 'ERROR: ' . $e->getMessage();
}

try {

    $result = $this->serwerSms->messages()->reports(['id' => ['aca3944055']]);

    foreach ($result->items as $sms) {
        echo 'ID: ' . $sms->id . '<br />';
        echo 'NUMER: ' . $sms->phone . '<br />';
        echo 'STATUS: ' . $sms->status . '<br />';
        echo 'SKOLEJKOWANO: '. $sms->queued . '<br />';
        echo 'WYSŁANO: ' . $sms->sent . '<br />';
        echo 'DORĘCZONO: ' . $sms->delivered . '<br />';
        echo 'NADAWCA: ' . $sms->sender . '<br />';
        echo 'TYP: ' . $sms->type . '<br />';
        echo 'WIADOMOŚĆ: ' . $sms->text . '<br />';
    }

} catch (\Exception $e) {
    echo 'ERROR: ' . $e->getMessage();
}

try {

    $result = $this->serwerSms->messages()->received('ndi');

    foreach ($result->items as $sms) {
        echo 'ID: ' . $sms->id . '<br />';
        echo 'TYP: ' . $sms->type . '<br />';
        echo 'NUMER: ' . $sms->phone . '<br />';
        echo 'DATA: ' . $sms->received . '<br />';
        echo 'CZARNA LISTA: ' . $sms->blacklist . '<br />';
        echo 'WIADOMOŚĆ: ' . $sms->text . '<br />';
    }

} catch (\Exception $e) {
    echo 'ERROR: ' . $e->getMessage();
}