PHP code example of demmonico / yii2-sms

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

    

demmonico / yii2-sms example snippets


return [
    //...
    'components' => [
        //...
        'sms' => [
            'class' => 'demmonico\sms\Sender',
            'senderNumber' => 'name' or 'number',
            'provider' => [
                'class' => 'demmonico\sms\Nexmo',
                'apiKey' => '***',
                'apiSecret' => '***',
            ],
        ],
    ],
];

$component = \Yii::createObject('demmonico\sms\Nexmo', [
    [
        'class' => 'demmonico\sms\Sender',
        'senderNumber' => 'name' or 'number',
        'provider' => [
            'class' => 'demmonico\sms\Nexmo',
            'apiKey' => '***',
            'apiSecret' => '***',
        ],
    ],
]);

return [
    //...
    'components' => [
        //...
        'sms' => [
            'class' => 'demmonico\sms\Sender',
            'senderNumber' => 'name' or 'number',
            'provider' => [
                'class' => 'demmonico\sms\Nexmo',
                'apiKey' => [
                    'component' => 'config',
                    'sms.Nexmo.apiKey',
                ],
                'apiSecret' => [
                    'component' => 'config',
                    'sms.Nexmo.apiSecret',
                ],
            ],
        ],
    ],
];

return [
    //...
    'sms.Nexmo.apiKey' => '******',
    'sms.Nexmo.apiSecret' => '******',
];

return [
    //...
    'components' => [
        //...
        'sms' => [
            //...
            'debug' => [
                'redirectNumber' => 'number',
                'dummyNumbers' => [
                    'number',
                    //...
                ],
            ],
        ],
    ],
];

Yii::$app->sms->sendSms('Hello, world!', 'number');

Yii::$app->sms->sendSms('Hello, world!', 'recipientNumber', 'senderNumber');

Yii::$app->sms->getBalance();

Yii::$app->sms->getNumbers();