Sending Sms with Cynsms Using laravel

Cyn SMS API is build for Cyn SMS - Bulk SMS Application For Marketing

Technical Requirements

For this tutorial we’ll assume you already know or have the following:

  • A Terminal (Command Line)
  • Composer installed
  • Are familiar with PHP
  • Are familiar with Laravel (5+)
  • You have an existing Laravel (5+) project
  • You have a Cynsns account and your credentials ready

Just in case you don’t have a Laravel project setup, this guide will help you to create a new Laravel project locally.

Install and Configure the Cynsms SDK

The first thing we need to do is install the Cynsms SDK which will provide the needed functions to get our SMS app started. We’ll use the command line to achieve that. So in the command line type:

Cyn SMS API

Prerequisites

php >=5.6
Cyn SMS - Bulk SMS Application For Markting

Installing

Via Composer

composer require cynojine/cynsms-api 

And Via Bash

git clone https://github.com/cynojine/cynsms-api.git

Usage

### Step 1: If install Cyn SMS API using Git Clone then load your Cyn SMS API Class file and Use namespace.

require_once 'src/Class_Cyn_SMS_API.php';
use CynSMS\CynSMSAPI;

If install Cyn SMS API using Composer then Require/Include autoload.php file in the index.php of your project or whatever file you need to use Cyn SMS API classes:.

require 'vendor/autoload.php';
use CynSMS\CynSMSAPI;

Step 2:

set your API_KEY from https://console.cynsms.online/sms-api/info

$api_key = 'YWRtaW46YWRtaW4ucGFzc3dvcmQ=';

Step 3:

Change the from number below. It can be a valid phone number or a String

$from = '2699655847554';

Step 4:

the number we are sending to - Any phone number

$destination = '8801810000000';

You have to must include Country code at beginning of the phone number.

Step 5:

Replace api URL like https://mywebhost.com/sms/api with https://console.cynsms.online/ sms/api

$url = 'https://cynsms.online/sms/api';

// SMS Body

$sms = 'test message from Cyn SMS';

// Unicode SMS

$unicode = '1'; //For Unicode message

// Voice SMS

$voice = '1'; //For voice message

// MMS SMS

$mms = '1'; //For mms message
$media_url = 'https://yourmediaurl.com'; //Insert your media url

// Schedule SMS

$schedule_date = '09/17/2018 10:20 AM'; //Date like this format: m/d/Y h:i A

// Create Plain/text SMS Body for request

$sms_body = array(
    'api_key' => $api_key,
    'to' => $destination,
    'from' => $from,
    'sms' => $sms
);

// Create Unicode SMS Body for request

$sms_body = array(
    'api_key' => $api_key,
    'to' => $destination,
    'from' => $from,
    'sms' => $sms,
    'unicode' => $unicode,
);

// Create Voice SMS Body for request

$sms_body = array(
    'api_key' => $api_key,
    'to' => $destination,
    'from' => $from,
    'sms' => $sms,
    'voice' => $voice,
);

// Create MMS SMS Body for request

$sms_body = array(
    'api_key' => $api_key,
    'to' => $destination,
    'from' => $from,
    'sms' => $sms, //optional
    'mms' => $mms,
    'media_url' => $media_url,
);

// Create Schedule SMS Body for request

$sms_body = array(
    'api_key' => $api_key,
    'to' => $destination,
    'from' => $from,
    'sms' => $sms,
    'schedule' => $schedule_date,
);

Step 6:

Instantiate a new Cyn SMS API request

$client = new CynSMSAPI();

Send SMS

Finally send your sms through Ultimate SMS API

$response = $client->send_sms($sms_body, $url);

Get Inbox

Get your all message

$get_inbox=$client->get_inbox($api_key,$url);

Get Balance

Get your account balance

$get_balance=$client->check_balance($api_key,$url);

Response

Cyn SMS API return response with json format, like:

{"code":"ok","message":"Successfully Send"}

Status Code

Status Message
ok Successfully Send
100 Bad gateway requested
101 Wrong action
102 Authentication failed
103 Invalid phone number
104 Phone coverage not active
105 Insufficient balance
106 Invalid Sender ID
107 Invalid SMS Type
108 SMS Gateway not active
109 Invalid Schedule Time
110 Media url required
111 SMS contain spam word. Wait for approval

Authors