繁体   English   中英

如何使用 Twilio API 将 SMS 发送到 PHP 阵列

[英]How to send SMS to a PHP array with Twilio API

使用 Twilio API,我的 PHP 可以发送到一个电话号码,并且可以成功发送。 我们希望从一个请求发送到多个号码,为此,我设置了一组数字进行迭代,但是,当我尝试通过点击 URL 发送消息时,我不断收到 500 错误。 下面是我正在使用的文件。

在 Linux 服务器上运行 PHP 7.2。 如果这很重要,我正在运行 CentOS 7.7 和 Apache 2.4.43。

// Require the bundled autoload file - the path may need to change
// based on where you downloaded and unzipped the SDK
require __DIR__ . '/twilio-php-master/src/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 = 'XXXXXXXX';
$token = 'XXXXXXXX';
$client = new Client($sid, $token);

$a = array('+15555555555', '+15555555556');

$bodyTxt = “This is a test of sending the text message to multiple phone numbers.”
// Use the client to do fun stuff like send text messages!

foreach ($a as $v) {
    $message = $twilio->messages
        $client->messages->create($v, // to
                           [
                               "body" => $bodyTxt,
                               "from" => "+15555555557",
                           ]
                  );
        print($message->sid);
}
);

我对 PHP 不是很熟悉,因为我主要从事营销工作,但我在这些疯狂的时期担任开发人员的职务,因为我知道足够危险。 我认为这与 foreach 部分有关,因为这是与单次发送不同的唯一部分。

任何帮助表示赞赏!

在@LuisE 的帮助下弄清楚了,我通过并找出了我在数组后面缺少分号的地方,$bodyTxt。 和 $message = $twilio->messages。

// Require the bundled autoload file - the path may need to change
// based on where you downloaded and unzipped the SDK
require __DIR__ . '/twilio-php-master/src/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 = 'XXXXXXXXXX';
$token = 'XXXXXXXXX';
$client = new Client($sid, $token);

$a = array('+15555555555', '+15555555556');

$bodyTxt = 'This is a test of sending the text message to multiple phone numbers.';
// Use the client to do fun stuff like send text messages!

foreach ($a as $v) {
    $message = $twilio->messages;
        $client->messages->create($v, // to
                           [
                               "body" => $bodyTxt,
                               "from" => "+15555555557",
                           ]
                  );
        print($message->sid);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM