简体   繁体   中英

Twilio PHP script returning code 500 error when on remote server, working fine on local server?

I have the following PHP script to send a verification text using 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);
?>

When I run it using http://localhost/sms.php?num=01115465467&country=Egypt and I change the directory for the autoload.php file to /Applications/XAMPP/xamppfiles/htdocs/twilio-php-master/Twilio/autoload.php (where it is installed on my computer), the script works fine. However, I uploaded it to a remote server, and tried using the directory /var/www/html/group1/twilio-php-master/autoload.php (where it is on the server) and running it on http://188.226.144.157/group1/sms.php?num=01115465467&country=Egypt , but my android app returns an error code of 500 when it tries to run the script.

The URL you have entered for the file location on your server is wrong, you have missed a directory http://188.226.144.157/group1/twilio-php-master/autoload.php returns 404

Whereas this works http://188.226.144.157/group1/twilio-php-master/Twilio/autoload.php

Try this
require '/var/www/html/group1/twilio-php-master/Twilio/autoload.php'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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