0

I have an online form that users fill and register. I want them to get an SMS alert notifying them that their registration was successful. I also have a routesms API.

When you type this link in a brower:

http://sms.brantilo.com:8080/bulksms/bulksms?username=xxxx&password=xxxx&type=0&dlr=1&destination=2348936454&source=FitzPiro&message=Thanks, Your Registration was Successful

it gets delivered to 2348936454 and returns a Message Delivered report.

Here is my code, which does not result in a received SMS message:

        //Send SMS and Email  Here


        define('jit_user','nem-piro');
        define('jit_pwd','xxxxxx');

        define('enable_sms',1);
        define('credit_load',5);

        define('smssenderid',"SampleID");

        if(enable_sms){
            $jit_user = jit_user;
            $jit_pwd = jit_pwd;
            $mobile = $data->mobile;
            $smsBody ="Hello {$surname} {$othername}, your registration was successful. Thank you!";
            $smsSender = smssenderid;
            $link = "http://sms.brantilo.com:8080/bulksms/bulksms?username={$jit_user}&password={$jit_pwd}&type=0&dlr=1&destination=" . urlencode($mobile) ."&source=" . urlencode($smsSender) ."&message=" .  urlencode($smsBody);
            $result = file_get_contents($link);
        }
        //Send SMS and Email Here

        $session->data['UTMEregnum'] = $reg;
        $session->data['data'] = $data;
        $session->save();

        $ref_from = "./utme-register-ok.php";   
    }else{
        $ref_from = "./register.php?err=signup_no"; 
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
Fitzpiro
  • 11
  • 4
  • 1
    What does "not working" mean in practice? Have you debugged where this might be getting stuck? – halfer Mar 16 '15 at 14:45
  • What I mean is that after successful registration, user doesn't get the sms confirmation. – Fitzpiro Mar 16 '15 at 15:36
  • OK, debugging time! Does the `file_get_contents()` run? Does it run successfully? Have you ensured there is no firewall in the way that would prevent a port 8080 request from leaving your server? – halfer Mar 16 '15 at 16:10
  • Does your SMS provider offer a web interface to examine received requests? Maybe it is reaching them but not getting to the target mobile phone? (As it stands, it is hard to help, as there are a lot of different possible problems that could be affecting you here). – halfer Mar 16 '15 at 16:12
  • thank you halfer, but as it is, the sms provider does not provide such web interface and I am using a shared server. How do i go about the firewall issue since It is a shared server? – Fitzpiro Mar 17 '15 at 15:41
  • if i input http://sms.brantilo.com:8080/bulksms/bulksms?username=... with a mobile number, it gets delivered – Fitzpiro Mar 17 '15 at 15:44
  • How do i go about the firewall issue since It is a shared server? is there an alternative to file_get_contents() should it be blocked by the host? – Fitzpiro Mar 17 '15 at 16:19
  • OK, if that URL works, it may not be a firewall issue (you have no control over that anyway on a shared server). Perhaps it would help if you edit your question to additionally: show the URL that works, and show the one that does not (of course, don't show any real phone numbers, unless they are your own). – halfer Mar 17 '15 at 16:24
  • No, the SMS provider does not offer a web interface to examine received requests – Fitzpiro Mar 17 '15 at 16:37
  • Ah, apologies - I didn't see that you'd already answered the question about the web interface. OK, that's frustrating - it would have been useful. You can always suggest it to your SMS provider. That said, maybe the API gives you error information? Have you checked `$result` when you get a non-delivery? What format is the data in - JSON? – halfer Mar 17 '15 at 16:38
  • @ Halfer, can you explain the data you mean? – Fitzpiro Mar 18 '15 at 15:05
  • I mean do `echo $result` - what format is it? It might contain information about the failure when it fails. – halfer Mar 18 '15 at 15:14
  • when I echo $result, I got a blank page. But data is captured in Array -JSON – Fitzpiro Mar 18 '15 at 16:15
  • Is it always blank? If so, how can data be captured as JSON as you claim? Maybe it's worth logging the output to a file, in case it is not correctly rendering to the screen. – halfer Mar 18 '15 at 16:20
  • Sorry about the JSON mix up. This line goes through on the browser http://sms.brantilo.com:8080/bulksms/bulksms?username=xxxx&password=xxxx&type=0&dlr=1&destination=234535533&source=FitzPiro&message=Successfully Registered. But this other line of code alone does not deliver the sms – Fitzpiro Mar 18 '15 at 16:35
  • Ah, I see what you mean. OK, you could add a stream context resource as a third parameter to `file_get_contents()` to see if there are any HTTP response headers indicating a failure. Or you [could do it this way](https://php.net/manual/en/reserved.variables.httpresponseheader.php), might be easier. – halfer Mar 18 '15 at 16:37
  • after apllying $http_response_header on the link, here is what was displayed array(5) { [0]=> string(15) "HTTP/1.1 200 OK" [1]=> string(25) "Server: Apache-Coyote/1.1" [2]=> string(37) "Content-Type: text/html;charset=UTF-8" [3]=> string(17) "Content-Length: 4" [4]=> string(35) "Date: Wed, 18 Mar 2015 16:48:45 GMT" } NULL – Fitzpiro Mar 18 '15 at 16:51
  • (If you could get into the habit of editing these useful items into your question using the formatting tools, and not adding them to comments, that would be appreciated - it is quite a common request on here. As you can see, it's not very readable. You can still ping people in the comments to say you've updated/answered). – halfer Mar 18 '15 at 16:59
  • "200 OK" means the call was successful, although it looks like the type (text/html) and content length (4) means that there is a problem on the remote side (both are unexpected, I think). Either it was OK, in which case you should get JSON, or there was an error, in which case you should get an error response code (and probably a JSON error message anyway). Contact their support department. – halfer Mar 18 '15 at 17:00
  • Its alright, I understand and also appreciate your support. I have contacted the sms gateway support and they said I should refer back to my codes. That everything is fine at their own end. What do I do now pls? – Fitzpiro Mar 18 '15 at 20:24
  • Well, it looks to me like the problem is at their end, since you have a situation where you are expecting a JSON response and are getting an HTML response instead. I imagine you should _always_ get a JSON response - maybe you could ask them if that is correct? Or point them to this page, of course. They may be unwilling to help in detail (large providers don't have either the right experience or enough time) so you may need to just change to a different provider. – halfer Mar 18 '15 at 20:29
  • Do you have a link to their online docs? Paste it here if you do. – halfer Mar 18 '15 at 20:31
  • Thanks halfer for all your efforts, here is the link http://routesms.com/downloads/document/SmsPlus_BulkHttp.pdf perhaps you will pay more attention on page 12 – Fitzpiro Mar 18 '15 at 22:50
  • Look at page 4 - that's not JSON at all. No wonder they told you to go away `:-)`. The `Content-Length` of 4 characters from earlier was correct, in that case - it's an error code. If you can't see it when you echo the result to the screen, run the code from the console (i.e. outside of the web environment) or log it to a temporary file, so you can look at it. (Their `Content-Type` of `text/html` isn't correct, but it doesn't really matter - it's just text). – halfer Mar 18 '15 at 23:09
  • @ halfer. Still showing a blank page. Can you help me look at the php API call script on page 12 of their online doc? Can it be a way out? If yes, how do i integrate it? – Fitzpiro Mar 19 '15 at 08:23
  • I think you need to persist getting that error code, so you can determine what the real problem is. Either echo it out in the web environment and search in your output carefully for it (it's only four characters long) or run this code in a console environment, so you don't have HTML distracting you from the key output. – halfer Mar 19 '15 at 08:36
  • Did you get solution @Fitzpiro – Pushpendra Singh Jun 11 '16 at 16:22

1 Answers1

-1
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/*******************************route1************************************************************************************************************/

$config['route1_url']=' ';

$config['route1_notify_url']='';

$config['route1_acc_blnce_url']='';

$config['route1_authorization_method']='Basic';

$config['route1_username']='Allsee';

$config['route1_password']='Techas12';

$config['route1_sms_validity_period']=360;

$config['route1']=1;

$config['route1_transliteration']="NON_UNICODE";

$config['route1_minimum_balance']=1000;

/***************************************route2****************************************************************************************************/

$config['route2_url']='';

$config['route2_notify_url']='';

$config['route2']=2;

$config['route2_username']='';

$config['route2_password']='';

$config['route2_dlr_value']=1;

$config['route2_bodytype']=1;

$config['route2_sms_validity_period']= ;

/**************************************************general******************************************************************************************/

$config['limitcount']= ;

$config['loopcount']= ;

$config['debug']=FALSE;
GrafiCode
  • 3,307
  • 3
  • 26
  • 31