php - 使用 PHP54 和 Twilio 发送消息时出现 Http 500 错误

标签 php sms twilio twilio-php twilio-api

    <?php
    // Require the bundled autoload file - the path may need to change
    // based on where you downloaded and unzipped the SDK
    require_once __DIR__ . '/twilio-php-master/Twilio/autoload.php';

    #require __DIR__ . '/var/sip10/public_html/htdocs/twilio/twilio-php-master/Twilio/autoload.php';

   // Use the REST API Client to make requests to the Twilio REST API
   use Twilio\Rest\Client;

   // Your Account SID and Auth Token from twilio.com/console
   $sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXX';
   $token = 'XXXXXXXXXXXXXXXXXXXXXXX';
   $client = new Client($sid, $token);


   // Use the client to do fun stuff like send text messages!

   $client->messages->create(
'+1XXXXXXXXXX',
array(
    'from' => '+1XXXXXXXXXX',
    'body' => "Hey Jenny! Good luck on the bar exam!"
)
);

?>

当我尝试向我的手机发送一条消息时,当所有正确的帐户信息都显示 http500 错误时,我测试了该库是否正常工作(是的),我知道它因为 $client->messages- 而变得困惑>创造但不明白为什么。

最佳答案

Twilio PHP 库依靠 cURL 发出 HTTP 请求,这些请求实际上会到达 Twilio 的 API 端点以发送您的消息。

您需要使 cURL 可用于您的 PHP。

  • 通过键入 sudo apt-get install curl 安装 cURL
  • 通过键入 sudo service apache2 restart 重新启动 Apache
  • 通过键入 sudo apt-get install php5-curl 安装 PHP5 cURL
  • 通过键入 sudo service apache2 restart 重新启动 Apache

请根据您的情况随意调整以上内容,但主要思想是 PHP 和 Twilio 库还不够,您还需要 cURL。

关于php - 使用 PHP54 和 Twilio 发送消息时出现 Http 500 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40428591/

相关文章:

java - 使用 smslib 获取短信的文本和发件人

linux - gammu-smsd RunOnReceive 脚本结果退出状态 2

validation - 验证手机号码

c# - 如何将传入的 SMS 解析为文本文件

php - 我可以使用通配符取消设置 PHP $_SESSION{} 变量吗?

php - 如何在 PHP Laravel 中验证复杂的 JSON 数组

java - 使用 Twilio Notify API 发送批量短信时,如何将状态 Webhook 回调绑定(bind)到原始消息?

android - Twilio 视频 :How to destroy video room when user who created it leaves it?

php - 我如何将 php 集成到 html 表中

php - sh : 0: getcwd() failed: No such file or directory from exec command