I can't send SMS with Twilio and Aloha library












0















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
    Nov 18 '18 at 23:31
















0















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
    Nov 18 '18 at 23:31














0












0








0








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 Nov 18 '18 at 23:25









philnash

38.1k93454




38.1k93454










asked Nov 18 '18 at 16:15









Aleks PerAleks Per

325219




325219













  • 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
    Nov 18 '18 at 23:31



















  • 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
    Nov 18 '18 at 23:31

















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
Nov 18 '18 at 23:31





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
Nov 18 '18 at 23:31












2 Answers
2






active

oldest

votes


















1














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
    Nov 18 '18 at 16:29











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

    – philnash
    Nov 18 '18 at 23:19



















1














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',
    autoActivateHeartbeat: false,
    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









    1














    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
      Nov 18 '18 at 16:29











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

      – philnash
      Nov 18 '18 at 23:19
















    1














    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
      Nov 18 '18 at 16:29











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

      – philnash
      Nov 18 '18 at 23:19














    1












    1








    1







    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 Nov 18 '18 at 16:22









    user1768610user1768610

    200315




    200315













    • I think its not possbile to send SMS from Twilio backofice

      – Aleks Per
      Nov 18 '18 at 16:29











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

      – philnash
      Nov 18 '18 at 23:19



















    • I think its not possbile to send SMS from Twilio backofice

      – Aleks Per
      Nov 18 '18 at 16:29











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

      – philnash
      Nov 18 '18 at 23:19

















    I think its not possbile to send SMS from Twilio backofice

    – Aleks Per
    Nov 18 '18 at 16:29





    I think its not possbile to send SMS from Twilio backofice

    – Aleks Per
    Nov 18 '18 at 16:29













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

    – philnash
    Nov 18 '18 at 23:19





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

    – philnash
    Nov 18 '18 at 23:19













    1














    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






























      1














      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




























        1












        1








        1







        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 Nov 19 '18 at 8:11

























        answered Nov 19 '18 at 0:27









        PolarisPolaris

        776113




        776113






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            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







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()