简体   繁体   中英

Twilio send an sms

Hello I have to verify the user phone numbers in my app. I have implemented twilio library but I am unable to send an sms. I am getting this error

Uncaught exception 'Services_Twilio_RestException' with message 'The From phone number +120xxxxxxx is not a valid, SMS-capable inbound phone number or short code for your account

I haven't bought their subscription yet. I want to first test their service so I am using trial account. I have used test AccountSID and Test authToken .

<?php

require "twilio/Services/Twilio.php";

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

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

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

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

From: when I clicked Get your first twilio phone number they given me one US mobile number which I used in From field

在此处输入图片说明

To: Here I have used my own number so that I can receive the text. My own number was used in twilio also for verification purposes

I basically want to use twilio to send random pin code from a number like "6323" or something like this. Please tell me what I am missing. And also they are giving me US number which I used in From field. How can I get the short number like "6323" or a alphabetical name like "whatsapp" in From field.

According to the docs :

Test Credentials

If you received this error while trying to authenticate with your Test Credentials, you probably tried to send a message with a From number from your live account. The only number that can be used to send successful messages with your Test Credentials is +15005550006. For more information, read our documentation on the From number for sending SMS with your test credentials.

So you need to hardcode +15005550006 as From .

For even more info on their API, see this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM