Http 500 Error Sending a Message using PHP54 and T

2019-05-15 06:30发布

    <?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!"
)
);

?>

When I try to Send a message to my phone when all the correct account information it says http500 error I tested if the library is working (yes it is) and I know it messes up because of the $client->messages->create but cannot understand why.

1条回答
狗以群分
2楼-- · 2019-05-15 06:46

The Twilio PHP library relies on cURL to make the HTTP requests that are actually hitting the Twilio's API endpoints to send your message.

You need to make cURL available to your PHP.

  • Install cURL by typing sudo apt-get install curl
  • Restart Apache by typing sudo service apache2 restart
  • Install PHP5 cURL by typing sudo apt-get install php5-curl
  • Restart Apache by typing sudo service apache2 restart

Feel free to adjust the above for your case, but the main idea is PHP and Twilio library is not enough, you also need cURL.

查看更多
登录 后发表回答