0

I have sms gateway which is used to send sms on Yii2 project. The sms is not going when i call that particular action where sms code is stored. if i print that sms url and copy paste in browser and hit it.. its going. I don't know whats wrong in Yii2.

Below is the action code and curl code is in model

  public function actionMessage() {  
        /*sms code start*/ 
                $model = new BillPersonal();

                $mobile = "9703843454";
                $authKey = "XXXXXXXXXXXXXX";
                $senderId = "XXXXXX";
                $textMessage = "Test Messsage"; 

                $url = sprintf("http://www.smsgatewayhub.com/api/mt/SendSMS?APIKey=".$authKey."&senderid=".$senderId."&channel=2&DCS=0&flashsms=0&number=91".$mobile."&text=".$textMessage."&route=11"); 

                $curl_handle = curl_init();
                      curl_setopt($curl_handle, CURLOPT_URL, $url);
                      curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 5);
                      curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
                      curl_setopt($curl_handle, CURLOPT_USERAGENT, 'CHMS');
                      $query = curl_exec($curl_handle);
       }
Salman Riyaz
  • 808
  • 2
  • 14
  • 37
  • Propably there's nothing wrong in Yii2, because youre not using Yii2 in this code. It's pure PHP, and what have you tried with debugging your `openurl()` method? – Yupik Oct 29 '17 at 12:53
  • Im running that url $url – Salman Riyaz Oct 29 '17 at 13:58
  • That's not debugging your `curl`. – Yupik Oct 30 '17 at 07:46
  • yes i think because of that sms is not going. – Salman Riyaz Oct 30 '17 at 08:57
  • So check what's wrong with your `curl`. – Yupik Oct 30 '17 at 09:14
  • @Yupik Code updated - I changes the CURL to above code.. then also its not working. – Salman Riyaz Oct 30 '17 at 12:15
  • But what's exacly is not working? Try to debug your curl request, for example like [that](https://stackoverflow.com/questions/3757071/php-debugging-curl) – Yupik Oct 30 '17 at 12:19
  • `http://www.smsgatewayhub.com/api/mt/SendSMS?APIKey=XXXXXXXXXXXXXXXXXXX&senderid=XXXXXXX&channel=2&DCS=0&flashsms=0&number=91XXXXXXXXX&text=Dear curl come&route=11` I have this url now.. please tell me from your side how do i run this url so that i send sms without browser? – Salman Riyaz Oct 30 '17 at 13:33
  • Salman, please focus for just one minute. I don't care about how the URL looks like, i care what is the result of executing your `curl()` - does thow any exception? What is exacly the output if it executes correctly (to check this follow the link which i gave you). – Yupik Oct 30 '17 at 13:42

1 Answers1

0

I finally got the solution.. The problem was with CURL settings. Hope this help someone.

public function actionSms(){

               $apikey = "XXXXXXXXXXXXXXXXXXX";
               $apisender = "XXXXXXXXX";
               $msg ="YOUR MESSAGE";
               $num = "91XXXXXXXXXXXX";     

               $ms = rawurlencode($msg);   

            $url = 'https://www.smsgatewayhub.com/api/mt/SendSMS?APIKey='.$apikey.'&senderid='.$apisender.'&channel=2&DCS=0&flashsms=0&number='.$num.'&text='.$ms.'&route=1';

             //echo $url;
             $ch=curl_init($url);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch,CURLOPT_POST,1);
             curl_setopt($ch,CURLOPT_POSTFIELDS,"");
             curl_setopt($ch, CURLOPT_RETURNTRANSFER,2);
             $data = curl_exec($ch);
             echo '<br/><br/>';
             print($data); /* result of API call*/
      }
Salman Riyaz
  • 808
  • 2
  • 14
  • 37