douche3791 2014-08-17 16:16
浏览 225
已采纳

在php中通过twilio发送短信

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?

  • 写回答

2条回答 默认 最新

  • duanlan7239 2014-08-19 07:18
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何实验stm32主通道和互补通道独立输出
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题