Sending SMS with PHP using Sendchamp SMS API

A quick walk-through on how to seamlessly implement Sendchamp SMS API with PHP

Aliyu Abubakar

Aug 2, 2021

Learn how to quickly send SMS messages with PHP using sendchamp API. In this guide we will walk you through:

  1. Signing up free sendchamp account
  2. Create a Sender ID
  3. Setting up a PHP Application
  4. Sending your first message

Prerequisite

Before you can get started, you need the following already set up: You have PHP installed. If you don't, read about how to install it on your system here.

  • A sendchamp account
  • Signing up free sendchamp account

If you already have an account? skip to the next section You can sign up for a free sendchamp account here.

image

When you sign up, you'll have to verify your email address. This allows sendchamp to verify your identity.

After you've verified your email address, you'll be asked a question in order to get you started in a way that's relevant to you.

After you finish setting up your account, you'll have access to your dashboard where you can access your API Key and perform dashboard communication functions.

Create a Sender ID

Once your account is created, you’ll need to add a new sender ID in order to send SMS Messages. Click channels on your dashboard under settings, click sms channel and add a sender ID. Take note of your ID, because you'll use it later.

image

Setting up a PHP Application

First, you’ll need to create a file send_sms.php to save your code.


<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://sandbox-api.sendchamp.com/api/v1/sms/send',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "to": ["2348055372961"],
    "message": "Hello from Olumide Latest",
    "sender_name": "Kuda"
    "route": "non_dnd"
}',
  CURLOPT_HTTPHEADER => array(
    'Accept: application/json',
    'Authorization: Bearer ACCESS_KEY',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Replace CURLOTP_URL with either a test or live BASE URL depending on what you intend to do.

Replace Authorization under CURLOTP_HTTPHEADER with your test or live Access key depending on what you intend.

Parameters

  • You need numbers to send messages to and from.
  • Set the value of (to) to any number (or numbers) you want to receive the message.
  • Set the value of the sender_name token to your Sender ID on your sendchamp dashboard.
  • set route to dnd, non_dnd or international.

Sending your SMS message

Now you can execute the code and send your test SMS message.

Run the following command:

php send_sms.php 

The code you used in the send_sms.php file sends a POST request to the sendchamp API endpoint to send the SMS message.

© 2022 Sendchamp. All rights reserved.