0

I tried to send an http url using curl but it didn't work at all, here is the code I've used:

<?php

$username = 'username';
$password = 'password';
$sender='sender';
$msisdn = '+96899999999';
$content="Test MSG";
$data = "username=".$username."&password=".$password."&message=".urlencode($content)."&sender=".$sender."&msisdn=".urlencode($msisdn);

$ch = curl_init('http://bulksms.vsms.net/eapi/submission/send_sms/2/2.0');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if ($response = curl_exec($ch)) 
{
  echo "1";
} 
 else 
{
   echo "0";
}

curl_close ($ch);
?>

It is always returning 0. What could be the problem?

Cristik
  • 30,989
  • 25
  • 91
  • 127
Arwa
  • 1
  • 2
  • you'll probably have to clarify your question along with adding a few examples of things you tried in order to receive any help. You can always update your question. Welcome to stack overflow, recommended reading: http://stackoverflow.com/help/how-to-ask – Dan Beaulieu May 12 '15 at 12:12

1 Answers1

0

Take a look at the BulkSMS API documentation for PHP. That provides comprehensive code for utilizing Curl to send a SMS.

Upon a quick inspection I see that they have a curl_setopt for the Port (443) and that their POST data is slightly different. The main difference is that yours has a sender field whereas their's does not.

  $ch = curl_init( );
  curl_setopt ( $ch, CURLOPT_URL, $url );
  curl_setopt ( $ch, CURLOPT_PORT, $port ); //443
  curl_setopt ( $ch, CURLOPT_POST, 1 );
  curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_body );
  // Allowing cUrl funtions 20 second to execute
  curl_setopt ( $ch, CURLOPT_TIMEOUT, 20 );
  // Waiting 20 seconds while trying to connect
  curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 20 );

  $response_string = curl_exec( $ch );
  $curl_info = curl_getinfo( $ch );

I would recommend just starting off with their code and trimming off what is not needed.

Bijan
  • 7,737
  • 18
  • 89
  • 149