PHP code example of betterapp / laravel-server-sms

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

    

betterapp / laravel-server-sms example snippets


    composer 

    php artisan vendor:publish



    return [
        'username' => 'username',
        'password' => 'password',
        'api_url'  => 'https://api2.serwersms.pl/',
        'format'   => 'json',
        'sender'   => '',
    ]


	try{
	
	    $serverSms = new \ServerSms;
	
	    // SMS FULL
	    $result = $serverSms->messages->sendSms(
	            array(
	                    '+48500600700',
	                    '+48600700800'
	            ),
	            'Test FULL message',
	            'INFORMACJA',
	            array(
	                    'test' => true,
	                    'details' => true
	            )
	    );
	
	    // SMS ECO
	    $result = $serverSms->messages->sendSms(
	            array(
	                    '+48500600700',
	                    '+48600700800'
	            ),
	            'Test ECO message',
	            null,
	            array(
	                    'test' => true,
	                    'details' => true
	            )
	    );
	
	    // VOICE from text
	    $result = $serverSms->messages->sendVoice(
	            array(
	                    '+48500600700',
	                    '+48600700800'
	            ),
	            array(
	                    'text' => 'Test message',
	                    'test' => true,
	                    'details' => true
	            )
	    );
	
	    // MMS
	    $list = $serverSms->files->index('mms');
	    $result = $serverSms->messages->sendMms(
	            array(
	                    '+48500600700',
	                    '+48600700800'
	            ),
	            'MMS Title',
	            array(
	                    '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{
	
	    $serverSms = new \ServerSms;
	
	    $messages[] = array(
			'phone' => '500600700',
			'text' => 'First message'
	    );
	    $messages[] = array(
			'phone' => '600700800',
			'text' => 'Second message'
	    );
	
	    $result = $serverSms->messages->sendPersonalized(
			$messages,
			'INFORMACJA',
			array(
					'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{
	
    	    $serverSms = new \ServerSms;
    	
    	    // Get messages reports
    	    $result = $serverSms->messages->reports(array('id' => array('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{
    	    $serverSms = new \ServerSms;
    	
    	    // Get recived messages
    	    $result = $serverSms->messages->recived('ndi');
    	
    	    foreach($result->items as $sms){
    	  
    	        echo 'ID: '.$sms->id.'<br />';
    	        echo 'TYP: '.$sms->type.'<br />';
    	        echo 'NUMER: '.$sms->phone.'<br />';
    	        echo 'DATA: '.$sms->recived.'<br />';
    	        echo 'CZARNA LISTA: '.$sms->blacklist.'<br />';
    	        echo 'WIADOMOŚĆ: '.$sms->text.'<br />';
    	        
    	    }
	
	} catch(Exception $e){
	    echo 'ERROR: '.$e->getMessage();
	}