1

I'm developing a web app using codeigniter,and i'm trying to send sms notifications using Twilio api,i tried using the twilio-ci library i found in github but it keep getting an error Curl failed with error Could not resolve host: api.twilio.com anyone has an idea on how to send sms using codeigniter and twilio?

S.Jandoubi
  • 41
  • 1
  • 4
  • Have you searched any of [similar problem](http://stackoverflow.com/questions/1341644/curl-and-https-cannot-resolve-host)s though? – Tpojka Mar 16 '16 at 16:25
  • Could you link the twilio-ci library that you found? I can't seem to find it. Also, have you tried the official Twilio PHP library? (https://github.com/twilio/twilio-php) – philnash Mar 16 '16 at 18:33

1 Answers1

0

I attempted to use the ci library when I was working on a Twilio project and it just never worked out.

While someone else pointed you to another answer, I do not believe it will work. Even when I was doing this last year the ci-library was badly out of date and I am not sure it has ever been updated

I would suggest using the standard Twilio Library. The only trick is you need to create a Helper file.

I will describe.

under the helper folder create a file my-twilio_helper.php

<?php
   if (!class_exists('Services_Twilio')) {
    include_once(APPPATH.'/libraries/Services/Twilio.php');
}

function get_twilio_service() {
    static $twilio_service;
    if (!($twilio_service instanceof Services_Twilio)) {

        $twilio_service = new Services_Twilio("sid", "auth");



    }
    return $twilio_service;
}

Then download the twilio Library into your libraries folder. You will just have a folder that says Services with all of the Twilio library inside.

After this I go into autoload.php and add it into my helper array like such

$autoload['helper'] = array("my-twilio", 'file');

Then in the controller files you call it

 //Calling the twilio help function to get the service
            $twilio = get_twilio_service();
            $sms = $twilio->account->messages->sendMessage(
                    'from', //from number 
                    $to, //To
                    'Message')

                    );
StevenDStanton
  • 841
  • 1
  • 7
  • 23