I can't send SMS with Twilio and Aloha library
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
add a comment |
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
Your code example doesn't close its brackets fully, is that the case in the actual app? Do you return or render anything from yoursend
method?
– philnash
Nov 18 '18 at 23:31
add a comment |
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
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
php laravel sms try-catch twilio
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 yoursend
method?
– philnash
Nov 18 '18 at 23:31
add a comment |
Your code example doesn't close its brackets fully, is that the case in the actual app? Do you return or render anything from yoursend
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
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 19 '18 at 8:11
answered Nov 19 '18 at 0:27
PolarisPolaris
776113
776113
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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