2

i am trying to send sms via php, and i cant get what is my problem. my account is verified and premium (not free), and the require once url is correct, and i changed the accountSid and AuthToken ,

require_once('twilio-php-master/Services/Twilio.php'); // Loads the library

// set your AccountSid and AuthToken from www.twilio.com/user/account
$AccountSid = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
$AuthToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$client = new Services_Twilio($AccountSid, $AuthToken);

$message = $client->account->messages->create(array(
    "From" => "+972527213871",
    "To" => "+972527213871",
    "Body" => "Test message!",
));

// Display a confirmation message on the screen
echo "Sent message {$message->sid}";

any help please?

5
  • 1
    You haven't mentioned what your problem actually is, are you getting an error message, is the twilio service sending back an error? Commented Aug 17, 2014 at 16:22
  • @PatrickEvans i am not getting not tje "Sent message" echo... and no errors and no sms Commented Aug 17, 2014 at 16:31
  • Do you have display_errors on and/or have you checked the server error logs? Commented Aug 17, 2014 at 16:38
  • No ... there is no errors....the problem i got is "From" number...how it works ?! @PatrickEvans Commented Aug 17, 2014 at 17:06
  • @MikhaMatta What is the problem with the from number? Is it different from what you specified? Commented Aug 17, 2014 at 17:52

2 Answers 2

5

There will be two problems possible:

1) SMS Sending not allowed for the Twilio number you purchased for area. 2) There may be some code error. From your code, am getting that you not defined the version of API.

The code worked for me is (for both paid or not paid accounts)

require_once('twilio-php-master/Services/Twilio.php'); // Loads the library

$version = "2010-04-01"; // Twilio REST API version

// Set our Account SID and AuthToken
$AccountSid = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
$AuthToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$client = new Services_Twilio($AccountSid, $AuthToken, $version); //initialise the Twilio client

try{
$message = $client->account->messages->create(array(
    "From" => "+972527213871",
    "To" => "+972527213871",
    "Body" => "Test message!",
));

// Display a confirmation message on the screen
echo "Sent message";
}catch (Exception $e) {
            echo 'Error: ' . $e->getMessage();
        }

You also check your logs in message section in your twilio account. If not showing any log then you can check in Developer Tools -> App Monitor.

You can refer this for more help: http://phpobserver.wordpress.com/2014/03/18/build-sms-text-message-into-your-web-apps-twilio-api/

I hope this will help you!

Sign up to request clarification or add additional context in comments.

Comments

3

Twilio evangelist here.

It looks like you are trying to send an SMS message from an Israeli phone number. Unfortunately today our Israeli local phone numbers do not offer messaging capabilities, only voice capabilities.

Hope that helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.