suriyansuresh
suriyansuresh

Reputation:

Using SMS Gateway API in PHP

i couldnt send sms using the following code, but i can sent sms using the same url, while i paste the url($murl) it into browser address bar

connection timed out, takes too much time to execute, but no result

what is the problem?

$amount="500";
$d="23-03-09";

$mNumber="98689988898";
$mName="TEST";
$mMessage ="\"We have debited Rs.$amount. Your account on $d.  Thank you for your valuable support.";
$u1 = 'http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?';
$u2= 'username='.urlencode('some').'&password='. urlencode('some').'&sendername='.urlencode('some') .'&mobileno='
. urlencode($mNumber).'&message='.urlencode($mMessage).'&submit=Submit';

$murl=$u1.$u2;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $murl);
//curl_setopt($ch, CURLOPT_HEADER, 1); 
//curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
/*curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $u2);
*/$response = curl_exec($ch);
print "Respons : $response";
curl_close($ch);

Upvotes: 0

Views: 3073

Answers (6)

debasish
debasish

Reputation: 745

<?php
if(isset($_POST['submit'])){
 $message=  rawurlencode($_POST['message']);
$phone=$_POST['phone'];
$url='http://sms.yourdomain.com/httpapi/smsapi?uname=xxxx&password=******&sender=XXXXX&receiver='.$phone.'&route=TA&msgtype=1&sms='.$message;
$ch = curl_init();
$header = array("Content-Type:application/json", "Accept:application/json");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_POST, 1);

// response of the POST request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$responseBody = json_decode($response);
curl_close($ch);
}
?>
<form action="sms.php" method="post">
Phone: <input type="text" name="phone"><br>
Message: <input type="text" name="message"><br>
<input type="submit" name="submit" value="sent">
</form>

Upvotes: 0

Rasika
Rasika

Reputation: 1998

Looking at the symptoms, I think this is an issue with firewall/access. Have you tried a script that just gets a page from the same site just to see that there is no firewall/proxy setting blocking the access. You could just use a command line web browser such as lynx to access the site from the server you are running the script to check whether the server is allowing the request to go out.

If you are game enough, run some packet sniffers to see whether any request packets are going out from the server.

Upvotes: 0

Nagar
Nagar

Reputation: 11

mysmsmantra is now available as a drupal module you can use the same with triggers and actions the module can be found at http://drupal.org/project/sms_mysmsmantra

Upvotes: 1

mattbasta
mattbasta

Reputation: 13709

Perhaps you need to set a user agent. The service you're using could be blocking the default user agent:

curl_setopt($ch, CURLOPT_USERAGENT, 'SMS Gateway Agent/1.0'); // Pick something creative, or use a browser UA

Hope this helps!

Upvotes: 0

raspi
raspi

Reputation: 6132

You can also omit curl with $response = file_get_contents($murl) if you don't need server side header answers. Check also http_build_query().

Upvotes: 0

jerebear
jerebear

Reputation: 6665

Change your code to this. Should work:

FROM

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $murl);

TO

$ch = curl_init($murl);

You can set the URL in the curl_init function as well.

Upvotes: 0

Related Questions