Http 500错误使用PHP54和Twilio发送消息

时间:2016-11-04 17:28:59

标签: 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-&gt;消息而混乱 - &gt;创建但无法理解原因。

1 个答案:

答案 0 :(得分:2)

Twilio PHP库依赖于cURL来实际发送到Twilio的API端点的HTTP请求来发送消息。

您需要为您的PHP提供cURL。

  • 输入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。

相关问题