Sending Voice Message with PHP using Sendchamp Voice API
A quick walk-through on how to seamlessly implement Sendchamp Voice API with PHP
Aliyu Abubakar
Aug 11, 2021
Learn how to quickly send voice messages with PHP using sendchamp API. In this guide we will walk you through:
- Signing up free sendchamp account
- Setting up a PHP Application
- 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.
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.
Setting up a PHP Application
First, you’ll need to create a file voice.php
to save your code.
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.sendchamp.com/api/v1/voice/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 =>'{
"customer_mobile_number": "2348119974190",
"message": "Hello from Olumide",
"type": "outgoing",
"repeat": 2
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Bearer SECRET_KEY'
),
));
$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
- Set the value of (customer_phone_number) to any number (or numbers) you want to receive the message.
- Set the value of the type to outgoing.
- Set (message) to the text message you want to send as voice.
Sending your voice message
Now you can execute the code and send your test SMS message.
Run the following command:
php voice.php
The code you used in the voice.php
file sends a POST request to the sendchamp API endpoint to send your voice message.