PHP code example of ondrejbalko / euro-sms
1. Go to this page and download the library: Download ondrejbalko/euro-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/ */
ondrejbalko / euro-sms example snippets
declare(strict_types=1);
\Entities\Message\Message;
use EuroSms\Entities\Recipient\Recipient;
use EuroSms\EuroSmsService;
use EuroSms\Exception\EuroSmsException;
try {
$config = new Config;
$config->setId(getenv('EUROSMS_ID') ?: '');
$config->setKey(getenv('EUROSMS_KEY') ?: '');
$config->setTestMode(true); // nothing is charged and nothing is delivered
$service = new EuroSmsService($config);
$message = new Message;
$message->setSenderName('MyShop');
$message->setContent('Your order is on its way.');
$message->setRecipient(new Recipient('0901 000 000'));
$result = $service->sendOne($message);
var_dump($result->getSent()); // the numbers the gateway took
var_dump($result->getFailed()); // the ones it refused, with the reason
} catch (EuroSmsException $e) {
// everything this library throws descends from EuroSmsException
error_log($e->getMessage());
}