Twilio PHP脚本在远程服务器上返回代码500错误,在本地服务器上正常工作?

时间:2017-06-23 17:41:28

标签: php twilio twilio-php

我有以下PHP脚本使用Twilio发送验证文本:

<?php

require '/twilio-php-master/Twilio/autoload.php';

// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;


$AccountSid = "xxx"; // Your Account SID from www.twilio.com/console

$AuthToken = "xxx";   // Your Auth Token from www.twilio.com/console

$client = new Client($AccountSid, $AuthToken);
$number = $_GET['num'];
$country = $_GET['country'];
$receivingPhone = "+2".$number;
$code = rand(100000, 999999);

$client->messages->create(
// the number you'd like to send the message to
$receivingPhone,
array(
    // A Twilio phone number you purchased at twilio.com/console
    'from' => '+12562947081',
    // the body of the text message you'd like to send
    'body' => $code
)
);
     $object = new stdClass();
     $object->num = $code;
     echo json_encode($object);
?>

当我使用http://localhost/sms.php?num=01115465467&country=Egypt运行它时,我将autoload.php文件的目录更改为/Applications/XAMPP/xamppfiles/htdocs/twilio-php-master/Twilio/autoload.php(安装它的位置)在我的电脑上),脚本工作正常。但是,我将它上传到远程服务器,并尝试使用目录/var/www/html/group1/twilio-php-master/autoload.php(它在服务器上)并在http://188.226.144.157/group1/sms.php?num=01115465467&country=Egypt上运行它,但我的Android应用程序在尝试运行脚本时返回错误代码500。

1 个答案:

答案 0 :(得分:1)

您为服务器上的文件位置输入的URL错误,您错过了一个目录 http://188.226.144.157/group1/twilio-php-master/autoload.php返回404

虽然这有效 http://188.226.144.157/group1/twilio-php-master/Twilio/autoload.php

试试这个 require '/var/www/html/group1/twilio-php-master/Twilio/autoload.php'