2

I am trying to get twilio to work with my website to send SMS.

Here are the steps i took,

First i downloaded the latest repo and put the Twilio folder under /libraries

then i added

$config['composer_autoload'] = '/libraries/Twilio/autoload.php';

to config/config.php

Then in my controller ,

I have a function that is,

$number = 'xx';
$country = '1';

$to = '+'.$country.$number;
require(APPPATH . "/libraries/Twilio/autoload.php");

// Use the REST API Client to make requests to the Twilio REST API
// Your Account SID and Auth Token from twilio.com/console
$sid = "xx"; // Your Account SID from www.twilio.com/console
$token = "xx";
$client = new Twilio\Rest\Client($sid, $token);

// Use the client to do fun stuff like send text messages!
$client->messages->create(
    // the number you'd like to send the message to
    $to,
    array(
        // A Twilio phone number you purchased at twilio.com/console
        'xxx' => 'ADD Your Free/purchased Number',
        // the body of the text message you'd like to send
        'body' => "Hey Emir! It's Works"
    )
);

So my problem is, when i run the view, this is the error i get,

A PHP Error was encountered

Severity: Warning

Message: require(/var/www/xxx.com/public_html/application/libraries/Twilio/Twilio/Rest/Client.php): failed to open stream: No such file or directory

So for some reason, Twilio/autoload.php adds another /Twilio in the path and i can't figure it out.

Any help?

Community
  • 1
  • 1
  • If you are using composer, have you tried requiring the composer autoload file instead of the Twilio autoload file directly? – McRed Jul 07 '17 at 18:11
  • @McRed how can i do that? There are literally no guides for codeigniter on twilio except outdated libraries so i am having hard time since couple hours to get it to work. –  Jul 07 '17 at 18:14
  • I think the problem might be that you are defining a composer autoload, but you didn't install the Twilio library with compose if you downloaded the latest repo and put it in the library folder yourself. You should be installing it with `composer require twilio/sdk`. Take a look at this [thread](https://stackoverflow.com/questions/39068783/codeignter-3-how-to-use-composer-packages-twilio-sdk) where they had a similar issue and were able to get the package installed properly with composer. – McRed Jul 07 '17 at 18:19
  • Another reference http://theprofessionguru.com/android/how-to-load-composers-vendor-autoloadphp-in-codeigniter – McRed Jul 07 '17 at 18:20
  • @McRed I did the steps, installed it with composer, my page loads when I do $client = new Client($sid, $token);, but then as soon as i do $client->messages->create ... the page don't open anymore and it gives internal server error –  Jul 07 '17 at 18:58
  • Well, if I do, $response = new Twiml; $response->say("Hello World!"); echo $response; it works perfectly, but as soon as i do $client->messages->create page don't open –  Jul 07 '17 at 19:13
  • To everyone, I got it fixed by doing $client->account->messages->create,thanks a lot. –  Jul 07 '17 at 19:31

1 Answers1

-2
    // Get the PHP helper library from twilio.com/docs/php/install
require_once 'Full/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account


$sid = "AC5ef872f6da5a21de157d80997a64bd33";
$token = "your_auth_token";
$client = new Client($sid, $token);
$client->messages->create(
    "+16518675309",
    array(
    'from' => "+14158141829",
    'body' => "Tomorrow's forecast in Financial District, San Francisco is Clear.",
   'mediaUrl' => "https://climacons.herokuapp.com/clear.png",
  )
);