Codeigniter – Sending SMS via PHP Codeigniter and email-to-SMS gateway

codeignitersms

I am trying to send a text message via the following in PHP Codeigniter.

If I send an email to the same "##########@vtext.com" from my gmail client, I receive the text message.

If I use the same code below but substitute my gmail account, I receive the message via email.

However, I cannot seem to trigger a text message sent to me via the code below.

I am thinking it may have something to do with a spam filter somewhere within the phone service.

Any suggestions, or else a free workaround for sending SMS via PHP/Codeigniter? Thanks!

public function textMe()
    {
        $this->load->library('email'); 
        $this->email->to('##########@vtext.com'); [number edited out]
        $this->email->from('Notify@test.org','Test'); 
        $this->email->subject("Test Subject"); 
        $this->email->message('Test Message'); 
        $this->email->send(); 
        echo $this->email->print_debugger();
    }

Best Answer

Codeigniter helper is useful in this case. Helper function will be available wherever needed. Save below file in Application/Heplers/sendsms_helper.php

 /*Start sendsms_helper.php file */

    function sendsms($number, $message_body, $return = '0'){       
        $sender = 'SEDEMO';  // Need to change
        $smsGatewayUrl = 'http://springedge.com';
        $apikey = '62q3z3hs49xxxxxx'; // Change   

        $textmessage = urlencode($textmessage);
        $api_element = '/api/web/send/';
        $api_params = $api_element.'?apikey='.$apikey.'&sender='.$sender.'&to='.$mobileno.
'&message='.$textmessage;    
        $smsgatewaydata = $smsGatewayUrl.$api_params;
        $url = $smsgatewaydata;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, false);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec($ch);
        curl_close($ch);        
        if(!$output){
           $output =  file_get_contents($smsgatewaydata);
        }

        if($return == '1'){
            return $output;            
        }else{
            echo "Sent";
        }        
    }

    /*     * End sendsms_helper.php file     */
  • ** Use:**
      1. Load sendsms helper as $this->load->helper('sendsms_helper');
      1. Call sendsms function Ex. sendsms( '919918xxxxxx', 'test message' );
Related Topic