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?
php laravel sms try-catch twilio
add a comment |
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?
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 yoursendmethod?
– philnash
yesterday
add a comment |
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?
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 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 yoursendmethod?
– philnash
yesterday
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 yoursendmethod?
– 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
add a comment |
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.
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
add a comment |
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.
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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 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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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 17 hours ago
answered yesterday
Polaris
71613
71613
add a comment |
add a comment |
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
sendmethod?– philnash
yesterday