Skip to content

Instantly share code, notes, and snippets.

@ruslanashaari
Forked from tsudot/plivo_curl.php
Created August 30, 2017 10:20
Show Gist options
  • Save ruslanashaari/2c8be88c1c23308fbfb1d5376c4a2589 to your computer and use it in GitHub Desktop.
Save ruslanashaari/2c8be88c1c23308fbfb1d5376c4a2589 to your computer and use it in GitHub Desktop.
Send an SMS using curl through Plivo.
<?php
# Plivo AUTH ID
$AUTH_ID = '';
# Plivo AUTH TOKEN
$AUTH_TOKEN = '';
# SMS sender ID.
$src = '';
# SMS destination number
$dst = '';
# SMS text
$text = '';
$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);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment