Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twizo SMS sending using CURL

Tags:

json

php

sms

I have been trying to send SMS using the API instructions from : https://www.twizo.com/developers/documentation/

$data = array(
    'sender'=>'Me',
    'body'=>'Message',
    'recipients'=>'201*****0'
);

$string = http_build_query($data);
$ch = curl_init("https://twizo:[email protected]/v1/sms/submitsimple");

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
print_r($server_output);

The code works but returns an error messasge :

{"validation_messages":{"recipients":{"noArraySupplied":"Only array values are allowed for this field"}},"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"Unprocessable Entity","status":422,"detail":"Failed Validation"}

EDIT2 : The above problem is fixed but now I want to make this work :

send.php file :

set_time_limit(0);
if(isset($_POST['submit'])){
$letter = $_POST['message'];
$recs = $_POST['rec'];
$mailist = $_POST['number'];
$from = $_POST["from"];
$message = $letter;
$line = 0;
$list = explode("\n",$_POST['number']);
foreach ($list as $number){ 
$line = $line+1;
}
?>
<H4>Total Number : <?php echo $line; ?> </H4>
<?php
$spamed = 0;
foreach ($list as $number){ 
$spamed = $spamed+1;
echo " ".$spamed."/".$line." ><b>".$number." => status :";
include "result.php";
}
}


result.php file :


sleep(0.7);
$message_array = array("https://silverstreet:[email protected]/v1/sms/submitsimple");
$mssage = array_rand($message_array);
$url = $message_array[$mssage];
$data = array(
  'body' => $message,
  'sender' => $from,
  'recipients' =>array("$recs")
); 
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$js = json_decode($result);
curl_close($ch);
if($js->message == "ok"){echo "sent";echo "<br>";} else {
if (!isset($js->message)){echo $result;
echo "<br>";
echo $url;
}else  {
echo "not sent <br> message  =";
echo  $js->message;
echo "<br>";
echo $url;}
like image 410
ZeroCode Avatar asked Nov 29 '25 01:11

ZeroCode


1 Answers

I think you need a second dimension array for recipients.

$data = array(
    'sender'=>'Me',
    'body'=>'Message',
    'recipients'=>array('201*****0')
);
like image 163
Jacques Barker Avatar answered Dec 01 '25 13:12

Jacques Barker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!