PHP code example of rm / smsender

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

    

rm / smsender example snippets


$message = new RM\SMSender\Message;
$message->setFrom('Example.com')
	->setTo('+421900123456')
	->setText('SMS text');
try {
	$smsender = new RM\SMSender\EuroSms\Sender([
		'id' => 'API-id',
		'key' => 'API-key',
	]);
	$smsender->send($message);
} catch (RM\SMSender\Exception $e) {
	echo 'ERROR: ' . $e->getMessage();
}

namespace App;

use Nette\Application\UI\Presenter;
use RM;

class SmsPresenter extends Presenter
{
	/** @var RM\SMSender\IMessageFactory @inject */
	public $messageFactory;

	/** @var RM\SMSender\ISender @inject */
	public $SMSender;

	protected function startup()
	{
		parent::startup();
		$this->SMSender->onBeforeSend[] = function ($message) {
			$message->setText($message->getText() . ' -- Example.com');
		};
		$this->SMSender->onSuccess[] = function () {
			$this->flashMessage('SMS has been sent.', 'success');
		};
		$this->SMSender->onError[] = function () {
			$this->flashMessage('Sending SMS failed.', 'warning');
		};
	}

	function actionSendSms($to, $text)
	{
		$message = $this->messageFactory->create();
		$message->setFrom('Example.com')
			->setTo($to)
			->setText($text);
		try {
			$this->SMSender->send($message);
		} catch (RM\SMSender\Exception $e) {}
	}
}