I'm trying to use Twilio's API to send a sms with PHP. I followed the tutorial as it is presented on their website but it doesn't work. I correctly replaced the $sid, $token, "from number" and "to number" variables. I also tested it with Phyton and it worked correctly, but with PHP I get the following error:
Fatal error: Uncaught Twilio\Exceptions\ConfigurationException: Credentials are required to create a Client in C:\xampp\htdocs\Php\Twilio\vendor\twilio\sdk\src\Twilio\Rest\Client.php:172 Stack trace: #0 C:\xampp\htdocs\Php\Twilio\index.php(13): Twilio\Rest\Client->__construct('', '') #1
I'm using PHP 7.3.21 and xampp. I've saw this same error with people using laravel and more complex codes, but I'm using "pure" PHP. The code I'm using:
<?php
// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once 'vendor/autoload.php';
use Twilio\Rest\Client;
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);
$message = $twilio->messages
->create("+15558675310", // to
[
"body" => "This is the ship that made the Kessel Run in fourteen parsecs?",
"from" => "+15017122661"
]
);
print($message->sid);
You can find the tutorial that I followed here: https://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-php