我正在尝试使用 Twilio 的 API 通过 PHP 发送短信。我按照他们网站上介绍的教程进行操作,但它不起作用。我正确地替换了 $sid、$token、“from number”和“to number”变量。我还用 Phyton 对其进行了测试,它工作正常,但使用 PHP 我得到以下错误:
致命错误:未捕获的 Twilio\Exceptions\ConfigurationException:在 C:\xampp\htdocs\Php\Twilio\vendor\twilio\sdk\src\Twilio\Rest\Client.php:172 堆栈跟踪:# 0 C:\xampp\htdocs\Php\Twilio\index.php(13): Twilio\Rest\Client->__construct('', '') #1
我正在使用 PHP 7.3.21 和 xampp。我在使用 laravel 和更复杂代码的人身上看到了同样的错误,但我使用的是“纯”PHP。我正在使用的代码:
<?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);
您可以在此处找到我遵循的教程:https ://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-php