Search code examples
phpapismsplivo

Unable to send sms using plivo api in php


I'm trying to send SMS using Plivo API in PHP but all methods are working fine and also get a response from Plivo but I'm not getting SMS from all these methods?

Source Code 1

# Plivo AUTH ID
$AUTH_ID = 'my id';
# Plivo AUTH TOKEN
$AUTH_TOKEN = 'my token';
# SMS sender ID.
$src = 'sender name';
# SMS destination number
$dst = '+92123456789';
# SMS text
$text = 'Hello';
$url = 'https://api.plivo.com/v1/Account/'.$AUTH_ID.'/Message/';
$data = array("src" => "$src", "dst" => "$dst", "text" => "$text");
$data_string = json_encode($data);
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_USERPWD, $AUTH_ID . ":" . $AUTH_TOKEN);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec( $ch );
curl_close($ch);
print_r($response);

Source Code 2

$auth_id = 'my auth id';
$auth_token = 'my token';
$src = 'sender number';
$dst = '+92123456789';

$text = 'Hello, this is testing message';

$api = curl_init("https://api.plivo.com/v1/Account/$auth_id/Message/");
curl_setopt_array($api, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_POST => 1,
    CURLOPT_HTTPHEADER => array("Authorization: Basic ".base64_encode($auth_id.':'.$auth_token)),
    CURLOPT_POSTFIELDS => array(
        'src' =>$src,
        'dst' => $dst,
        'text' => $text
    )
));

$resp = curl_exec($api);

$resp = curl_exec($api);
curl_close($api);

var_dump($resp);

Source Code 3

require 'vendor/autoload.php';
use Plivo\RestClient;

$client = new RestClient("auth_id", "auth_token");
$response = $client->messages->create(
    'sender number', // Sender's phone number with country code
    ['+92123456789'], // receiver's phone number with country code
    "Hello, this is a sample text", // Your SMS text message        
    ["url"=>"http://test.com/plivoapi/"]
);
print_r($response);

I have tried all these methods to send the SMS unable to get SMS using Plivo even I have tried to get SMS with the different countries number

Please guide me where I'm doing wrong or I need to add a webhook URL in Plivo API for the sending SMS?


Solution

  • From looking up the destination number in the question, it looks like that's an invalid number. If you still need help here, your best bet would be to create a support ticket.