2016-11-04 54 views
3
<?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->创建而变得混乱,但无法理解为什么。HTTP 500错误发送使用PHP54和Twilio

+0

你能发布你得到确切的错误消息吗? – philnash

+0

欢迎来到Stack Overflow Mandeep!你确定Twilio确实能够访问你的服务器吗? https://www.twilio.com/blog/2015/09/6-awesome-reasons-to-use-ngrok-when-testing-webhooks.html –

回答

2

Twilio PHP库依靠cURL使实际上击中Twilio的API端点的HTTP请求发送消息。

您需要将cURL提供给您的PHP。

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

随意调整上面安装卷曲你的情况,但主要想法是PHP和Twilio库不够用,你还需要cURL。