I can't send SMS with Twilio and Aloha library











up vote
0
down vote

favorite












I'm using Laravel 5.1 and I want to send SMS messages so I installed Aloha library:
https://github.com/aloha/laravel-twilio



I edited .env file with :



TWILIO_SID=AC7556934234234234234uuuuuuuuuu3
TWILIO_TOKEN=ca8xxxxxb9b60e66666666666666d355cfe315
TWILIO_FROM=+555555555555


Now I try to send a SMS with code:



...
use Twilio;
use IlluminateDatabaseEloquentModel;
use AlohaTwilioTwilioInterface;
use Services_Twilio_RestException;

class AdminController extends Controller {

public function send() {
try {
Twilio::message('+77777777777', 'test test test');
} catch (Services_Twilio_RestException $e) {
dd($e);
}


When I run function send() nothing happens (blank white screen) - no error with catch{} but also I don't receive SMS. When I look at Twilio SMS log there is nothing also.



How I can get an error message?
WHy this code doesn't send a message?










share|improve this question
























  • Your code example doesn't close its brackets fully, is that the case in the actual app? Do you return or render anything from your send method?
    – philnash
    yesterday















up vote
0
down vote

favorite












I'm using Laravel 5.1 and I want to send SMS messages so I installed Aloha library:
https://github.com/aloha/laravel-twilio



I edited .env file with :



TWILIO_SID=AC7556934234234234234uuuuuuuuuu3
TWILIO_TOKEN=ca8xxxxxb9b60e66666666666666d355cfe315
TWILIO_FROM=+555555555555


Now I try to send a SMS with code:



...
use Twilio;
use IlluminateDatabaseEloquentModel;
use AlohaTwilioTwilioInterface;
use Services_Twilio_RestException;

class AdminController extends Controller {

public function send() {
try {
Twilio::message('+77777777777', 'test test test');
} catch (Services_Twilio_RestException $e) {
dd($e);
}


When I run function send() nothing happens (blank white screen) - no error with catch{} but also I don't receive SMS. When I look at Twilio SMS log there is nothing also.



How I can get an error message?
WHy this code doesn't send a message?










share|improve this question
























  • Your code example doesn't close its brackets fully, is that the case in the actual app? Do you return or render anything from your send method?
    – philnash
    yesterday













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm using Laravel 5.1 and I want to send SMS messages so I installed Aloha library:
https://github.com/aloha/laravel-twilio



I edited .env file with :



TWILIO_SID=AC7556934234234234234uuuuuuuuuu3
TWILIO_TOKEN=ca8xxxxxb9b60e66666666666666d355cfe315
TWILIO_FROM=+555555555555


Now I try to send a SMS with code:



...
use Twilio;
use IlluminateDatabaseEloquentModel;
use AlohaTwilioTwilioInterface;
use Services_Twilio_RestException;

class AdminController extends Controller {

public function send() {
try {
Twilio::message('+77777777777', 'test test test');
} catch (Services_Twilio_RestException $e) {
dd($e);
}


When I run function send() nothing happens (blank white screen) - no error with catch{} but also I don't receive SMS. When I look at Twilio SMS log there is nothing also.



How I can get an error message?
WHy this code doesn't send a message?










share|improve this question















I'm using Laravel 5.1 and I want to send SMS messages so I installed Aloha library:
https://github.com/aloha/laravel-twilio



I edited .env file with :



TWILIO_SID=AC7556934234234234234uuuuuuuuuu3
TWILIO_TOKEN=ca8xxxxxb9b60e66666666666666d355cfe315
TWILIO_FROM=+555555555555


Now I try to send a SMS with code:



...
use Twilio;
use IlluminateDatabaseEloquentModel;
use AlohaTwilioTwilioInterface;
use Services_Twilio_RestException;

class AdminController extends Controller {

public function send() {
try {
Twilio::message('+77777777777', 'test test test');
} catch (Services_Twilio_RestException $e) {
dd($e);
}


When I run function send() nothing happens (blank white screen) - no error with catch{} but also I don't receive SMS. When I look at Twilio SMS log there is nothing also.



How I can get an error message?
WHy this code doesn't send a message?







php laravel sms try-catch twilio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









philnash

36.1k93353




36.1k93353










asked yesterday









Aleks Per

311217




311217












  • Your code example doesn't close its brackets fully, is that the case in the actual app? Do you return or render anything from your send method?
    – philnash
    yesterday


















  • Your code example doesn't close its brackets fully, is that the case in the actual app? Do you return or render anything from your send method?
    – philnash
    yesterday
















Your code example doesn't close its brackets fully, is that the case in the actual app? Do you return or render anything from your send method?
– philnash
yesterday




Your code example doesn't close its brackets fully, is that the case in the actual app? Do you return or render anything from your send method?
– philnash
yesterday












2 Answers
2






active

oldest

votes

















up vote
1
down vote













Go to Twilio web console and try sending messages. It typically gives a message or error code if a message is not sent successfully.



I have faced issues with Twilio not sending messages due to Country specific telecom policy for not accepting messages from unsolicited users/accounts.






share|improve this answer





















  • I think its not possbile to send SMS from Twilio backofice
    – Aleks Per
    yesterday










  • You can test out Twilio API endpoints in the Twilio console using the API explorer.
    – philnash
    yesterday


















up vote
1
down vote













Avid Twilio user here. I would recommend using Twilio's native PHP SDK over aloha/twilio. By default, I believe aloha/twilio pulls in twilio/sdk as it depends upon it, but I would remove aloha/twilio and just use twilio/sdk.



composer require twilio/sdk


I would then recommend creating a Twilio class inside say Services/Twilio.php where you can inject Twilio's client, create a new instance and instantiate it with your twilio config data. In this Service class, you could now put all of your Twilio methods like sendSMS(), sendMMS(), validatePhoneNumber(), etc and have access to them by injecting the new Twilio service class into your controller's constructor.



It might look like this:



Note that my implementation of sendSMS() uses a MessagingServiceSid and not a from number. You can replace 'messagingServiceSid' with 'from' if you are not utilizing a Twilio CoPilot Messaging Service in their platform.



Services/Twilio.php



namespace AppServices;

use TwilioRestClient;

class Twilio
{


/**
* @var Client
*/
protected $twilio;


public function __construct() {
try {
$this->twilio = new Client(config('twilio.SID'), config('twilio.TOKEN'));
}
catch (Exception $e) {
//do something with the exception, client could not be instantiated.
}
}

//My sendSMS allows for the passing of an array in the $to argument, letting you send to
//multiple numbers (or just one)
public function sendSMS($to, $message)
{
if (is_array($to)) {
foreach($to as $value) {
$this->twilio->messages->create($value, ['messagingServiceSid' => config('twilio.MESSAGING_SERVICE_SID'), 'body' => $message]);
}
return true;
}
$this->twilio->messages->create($to, ['messagingServiceSid' => config('twilio.MESSAGING_SERVICE_SID'), 'body' => $message]);
}
}


AdminController.php



use AppServicesTwilio;

class AdminController extends Controller {

protected $twilio;
public function __construct(Twilio $twilio)
{
$this->twilio = $twilio;
}

public function index()
{
$this->twilio->sendSMS('5551234567', 'Test message');
return 'Message was sent.';
}

}


If you implement Twilio in this way, you will be able to use any of the Twilio logic inside your controller without having to repeatedly create a new Twilio client or pass any of the config data.



I hope this helps.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53362939%2fi-cant-send-sms-with-twilio-and-aloha-library%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Go to Twilio web console and try sending messages. It typically gives a message or error code if a message is not sent successfully.



    I have faced issues with Twilio not sending messages due to Country specific telecom policy for not accepting messages from unsolicited users/accounts.






    share|improve this answer





















    • I think its not possbile to send SMS from Twilio backofice
      – Aleks Per
      yesterday










    • You can test out Twilio API endpoints in the Twilio console using the API explorer.
      – philnash
      yesterday















    up vote
    1
    down vote













    Go to Twilio web console and try sending messages. It typically gives a message or error code if a message is not sent successfully.



    I have faced issues with Twilio not sending messages due to Country specific telecom policy for not accepting messages from unsolicited users/accounts.






    share|improve this answer





















    • I think its not possbile to send SMS from Twilio backofice
      – Aleks Per
      yesterday










    • You can test out Twilio API endpoints in the Twilio console using the API explorer.
      – philnash
      yesterday













    up vote
    1
    down vote










    up vote
    1
    down vote









    Go to Twilio web console and try sending messages. It typically gives a message or error code if a message is not sent successfully.



    I have faced issues with Twilio not sending messages due to Country specific telecom policy for not accepting messages from unsolicited users/accounts.






    share|improve this answer












    Go to Twilio web console and try sending messages. It typically gives a message or error code if a message is not sent successfully.



    I have faced issues with Twilio not sending messages due to Country specific telecom policy for not accepting messages from unsolicited users/accounts.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered yesterday









    user1768610

    180215




    180215












    • I think its not possbile to send SMS from Twilio backofice
      – Aleks Per
      yesterday










    • You can test out Twilio API endpoints in the Twilio console using the API explorer.
      – philnash
      yesterday


















    • I think its not possbile to send SMS from Twilio backofice
      – Aleks Per
      yesterday










    • You can test out Twilio API endpoints in the Twilio console using the API explorer.
      – philnash
      yesterday
















    I think its not possbile to send SMS from Twilio backofice
    – Aleks Per
    yesterday




    I think its not possbile to send SMS from Twilio backofice
    – Aleks Per
    yesterday












    You can test out Twilio API endpoints in the Twilio console using the API explorer.
    – philnash
    yesterday




    You can test out Twilio API endpoints in the Twilio console using the API explorer.
    – philnash
    yesterday












    up vote
    1
    down vote













    Avid Twilio user here. I would recommend using Twilio's native PHP SDK over aloha/twilio. By default, I believe aloha/twilio pulls in twilio/sdk as it depends upon it, but I would remove aloha/twilio and just use twilio/sdk.



    composer require twilio/sdk


    I would then recommend creating a Twilio class inside say Services/Twilio.php where you can inject Twilio's client, create a new instance and instantiate it with your twilio config data. In this Service class, you could now put all of your Twilio methods like sendSMS(), sendMMS(), validatePhoneNumber(), etc and have access to them by injecting the new Twilio service class into your controller's constructor.



    It might look like this:



    Note that my implementation of sendSMS() uses a MessagingServiceSid and not a from number. You can replace 'messagingServiceSid' with 'from' if you are not utilizing a Twilio CoPilot Messaging Service in their platform.



    Services/Twilio.php



    namespace AppServices;

    use TwilioRestClient;

    class Twilio
    {


    /**
    * @var Client
    */
    protected $twilio;


    public function __construct() {
    try {
    $this->twilio = new Client(config('twilio.SID'), config('twilio.TOKEN'));
    }
    catch (Exception $e) {
    //do something with the exception, client could not be instantiated.
    }
    }

    //My sendSMS allows for the passing of an array in the $to argument, letting you send to
    //multiple numbers (or just one)
    public function sendSMS($to, $message)
    {
    if (is_array($to)) {
    foreach($to as $value) {
    $this->twilio->messages->create($value, ['messagingServiceSid' => config('twilio.MESSAGING_SERVICE_SID'), 'body' => $message]);
    }
    return true;
    }
    $this->twilio->messages->create($to, ['messagingServiceSid' => config('twilio.MESSAGING_SERVICE_SID'), 'body' => $message]);
    }
    }


    AdminController.php



    use AppServicesTwilio;

    class AdminController extends Controller {

    protected $twilio;
    public function __construct(Twilio $twilio)
    {
    $this->twilio = $twilio;
    }

    public function index()
    {
    $this->twilio->sendSMS('5551234567', 'Test message');
    return 'Message was sent.';
    }

    }


    If you implement Twilio in this way, you will be able to use any of the Twilio logic inside your controller without having to repeatedly create a new Twilio client or pass any of the config data.



    I hope this helps.






    share|improve this answer



























      up vote
      1
      down vote













      Avid Twilio user here. I would recommend using Twilio's native PHP SDK over aloha/twilio. By default, I believe aloha/twilio pulls in twilio/sdk as it depends upon it, but I would remove aloha/twilio and just use twilio/sdk.



      composer require twilio/sdk


      I would then recommend creating a Twilio class inside say Services/Twilio.php where you can inject Twilio's client, create a new instance and instantiate it with your twilio config data. In this Service class, you could now put all of your Twilio methods like sendSMS(), sendMMS(), validatePhoneNumber(), etc and have access to them by injecting the new Twilio service class into your controller's constructor.



      It might look like this:



      Note that my implementation of sendSMS() uses a MessagingServiceSid and not a from number. You can replace 'messagingServiceSid' with 'from' if you are not utilizing a Twilio CoPilot Messaging Service in their platform.



      Services/Twilio.php



      namespace AppServices;

      use TwilioRestClient;

      class Twilio
      {


      /**
      * @var Client
      */
      protected $twilio;


      public function __construct() {
      try {
      $this->twilio = new Client(config('twilio.SID'), config('twilio.TOKEN'));
      }
      catch (Exception $e) {
      //do something with the exception, client could not be instantiated.
      }
      }

      //My sendSMS allows for the passing of an array in the $to argument, letting you send to
      //multiple numbers (or just one)
      public function sendSMS($to, $message)
      {
      if (is_array($to)) {
      foreach($to as $value) {
      $this->twilio->messages->create($value, ['messagingServiceSid' => config('twilio.MESSAGING_SERVICE_SID'), 'body' => $message]);
      }
      return true;
      }
      $this->twilio->messages->create($to, ['messagingServiceSid' => config('twilio.MESSAGING_SERVICE_SID'), 'body' => $message]);
      }
      }


      AdminController.php



      use AppServicesTwilio;

      class AdminController extends Controller {

      protected $twilio;
      public function __construct(Twilio $twilio)
      {
      $this->twilio = $twilio;
      }

      public function index()
      {
      $this->twilio->sendSMS('5551234567', 'Test message');
      return 'Message was sent.';
      }

      }


      If you implement Twilio in this way, you will be able to use any of the Twilio logic inside your controller without having to repeatedly create a new Twilio client or pass any of the config data.



      I hope this helps.






      share|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        Avid Twilio user here. I would recommend using Twilio's native PHP SDK over aloha/twilio. By default, I believe aloha/twilio pulls in twilio/sdk as it depends upon it, but I would remove aloha/twilio and just use twilio/sdk.



        composer require twilio/sdk


        I would then recommend creating a Twilio class inside say Services/Twilio.php where you can inject Twilio's client, create a new instance and instantiate it with your twilio config data. In this Service class, you could now put all of your Twilio methods like sendSMS(), sendMMS(), validatePhoneNumber(), etc and have access to them by injecting the new Twilio service class into your controller's constructor.



        It might look like this:



        Note that my implementation of sendSMS() uses a MessagingServiceSid and not a from number. You can replace 'messagingServiceSid' with 'from' if you are not utilizing a Twilio CoPilot Messaging Service in their platform.



        Services/Twilio.php



        namespace AppServices;

        use TwilioRestClient;

        class Twilio
        {


        /**
        * @var Client
        */
        protected $twilio;


        public function __construct() {
        try {
        $this->twilio = new Client(config('twilio.SID'), config('twilio.TOKEN'));
        }
        catch (Exception $e) {
        //do something with the exception, client could not be instantiated.
        }
        }

        //My sendSMS allows for the passing of an array in the $to argument, letting you send to
        //multiple numbers (or just one)
        public function sendSMS($to, $message)
        {
        if (is_array($to)) {
        foreach($to as $value) {
        $this->twilio->messages->create($value, ['messagingServiceSid' => config('twilio.MESSAGING_SERVICE_SID'), 'body' => $message]);
        }
        return true;
        }
        $this->twilio->messages->create($to, ['messagingServiceSid' => config('twilio.MESSAGING_SERVICE_SID'), 'body' => $message]);
        }
        }


        AdminController.php



        use AppServicesTwilio;

        class AdminController extends Controller {

        protected $twilio;
        public function __construct(Twilio $twilio)
        {
        $this->twilio = $twilio;
        }

        public function index()
        {
        $this->twilio->sendSMS('5551234567', 'Test message');
        return 'Message was sent.';
        }

        }


        If you implement Twilio in this way, you will be able to use any of the Twilio logic inside your controller without having to repeatedly create a new Twilio client or pass any of the config data.



        I hope this helps.






        share|improve this answer














        Avid Twilio user here. I would recommend using Twilio's native PHP SDK over aloha/twilio. By default, I believe aloha/twilio pulls in twilio/sdk as it depends upon it, but I would remove aloha/twilio and just use twilio/sdk.



        composer require twilio/sdk


        I would then recommend creating a Twilio class inside say Services/Twilio.php where you can inject Twilio's client, create a new instance and instantiate it with your twilio config data. In this Service class, you could now put all of your Twilio methods like sendSMS(), sendMMS(), validatePhoneNumber(), etc and have access to them by injecting the new Twilio service class into your controller's constructor.



        It might look like this:



        Note that my implementation of sendSMS() uses a MessagingServiceSid and not a from number. You can replace 'messagingServiceSid' with 'from' if you are not utilizing a Twilio CoPilot Messaging Service in their platform.



        Services/Twilio.php



        namespace AppServices;

        use TwilioRestClient;

        class Twilio
        {


        /**
        * @var Client
        */
        protected $twilio;


        public function __construct() {
        try {
        $this->twilio = new Client(config('twilio.SID'), config('twilio.TOKEN'));
        }
        catch (Exception $e) {
        //do something with the exception, client could not be instantiated.
        }
        }

        //My sendSMS allows for the passing of an array in the $to argument, letting you send to
        //multiple numbers (or just one)
        public function sendSMS($to, $message)
        {
        if (is_array($to)) {
        foreach($to as $value) {
        $this->twilio->messages->create($value, ['messagingServiceSid' => config('twilio.MESSAGING_SERVICE_SID'), 'body' => $message]);
        }
        return true;
        }
        $this->twilio->messages->create($to, ['messagingServiceSid' => config('twilio.MESSAGING_SERVICE_SID'), 'body' => $message]);
        }
        }


        AdminController.php



        use AppServicesTwilio;

        class AdminController extends Controller {

        protected $twilio;
        public function __construct(Twilio $twilio)
        {
        $this->twilio = $twilio;
        }

        public function index()
        {
        $this->twilio->sendSMS('5551234567', 'Test message');
        return 'Message was sent.';
        }

        }


        If you implement Twilio in this way, you will be able to use any of the Twilio logic inside your controller without having to repeatedly create a new Twilio client or pass any of the config data.



        I hope this helps.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 17 hours ago

























        answered yesterday









        Polaris

        71613




        71613






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53362939%2fi-cant-send-sms-with-twilio-and-aloha-library%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Feedback on college project

            Futebolista

            Albești (Vaslui)