在 php 中通过 twilio 发送短信 [英] sending sms via twilio in php

查看:32
本文介绍了在 php 中通过 twilio 发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 php 发送短信,但我不知道我的问题是什么.我的帐户已经过验证和付费(不是免费的),并且需要一次 url 正确,我更改了 accountSid 和 AuthToken ,

i am trying to send sms via php, and i cant get what is my problem. my account is verified and premium (not free), and the require once url is correct, and i changed the accountSid and AuthToken ,

require_once('twilio-php-master/Services/Twilio.php'); // Loads the library

// set your AccountSid and AuthToken from www.twilio.com/user/account
$AccountSid = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
$AuthToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$client = new Services_Twilio($AccountSid, $AuthToken);

$message = $client->account->messages->create(array(
    "From" => "+972527213871",
    "To" => "+972527213871",
    "Body" => "Test message!",
));

// Display a confirmation message on the screen
echo "Sent message {$message->sid}";

有什么帮助吗?

推荐答案

可能会出现两个问题:

1) 您为该地区购买的 Twilio 号码不允许发送短信.2) 可能有一些代码错误.从您的代码中得知您没有定义 API 版本.

1) SMS Sending not allowed for the Twilio number you purchased for area. 2) There may be some code error. From your code, am getting that you not defined the version of API.

对我有用的代码是(对于付费或非付费帐户)

The code worked for me is (for both paid or not paid accounts)

require_once('twilio-php-master/Services/Twilio.php'); // Loads the library

$version = "2010-04-01"; // Twilio REST API version

// Set our Account SID and AuthToken
$AccountSid = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
$AuthToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$client = new Services_Twilio($AccountSid, $AuthToken, $version); //initialise the Twilio client

try{
$message = $client->account->messages->create(array(
    "From" => "+972527213871",
    "To" => "+972527213871",
    "Body" => "Test message!",
));

// Display a confirmation message on the screen
echo "Sent message";
}catch (Exception $e) {
            echo 'Error: ' . $e->getMessage();
        }

您还可以在您的 twilio 帐户的消息部分检查您的日志.如果没有显示任何日志,那么您可以检查开发者工具 -> 应用监视器.

You also check your logs in message section in your twilio account. If not showing any log then you can check in Developer Tools -> App Monitor.

你可以参考这个以获得更多帮助:http://phpobserver.wordpress.com/2014/03/18/build-sms-text-message-into-your-web-apps-twilio-api/

You can refer this for more help: http://phpobserver.wordpress.com/2014/03/18/build-sms-text-message-into-your-web-apps-twilio-api/

希望对你有帮助!

这篇关于在 php 中通过 twilio 发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆