3

I had twilio working for some time now, but I wanted to make some changes and save the numbers that are coming with sending errors in a database to avoid sending them again, and somehow, Twilio stopped working. I used it from the browser which shows no errors, but I got these errors when I tried to run the script file from the command line.

Any help is appreciated.

PHP Notice:  Use of undefined constant CURLOPT_URL - assumed 'CURLOPT_URL' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 80
PHP Notice:  Use of undefined constant CURLOPT_HEADER - assumed 'CURLOPT_HEADER' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 81
PHP Notice:  Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 82
PHP Notice:  Use of undefined constant CURLOPT_INFILESIZE - assumed 'CURLOPT_INFILESIZE' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 83
PHP Notice:  Use of undefined constant CURLOPT_HTTPHEADER - assumed 'CURLOPT_HTTPHEADER' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 84
PHP Notice:  Use of undefined constant CURLOPT_TIMEOUT - assumed 'CURLOPT_TIMEOUT' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 85
PHP Notice:  Use of undefined constant CURLOPT_HTTPHEADER - assumed 'CURLOPT_HTTPHEADER' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 89
PHP Notice:  Use of undefined constant CURLOPT_HTTPHEADER - assumed 'CURLOPT_HTTPHEADER' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 89
PHP Notice:  Use of undefined constant CURLOPT_HTTPHEADER - assumed 'CURLOPT_HTTPHEADER' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 89
PHP Notice:  Use of undefined constant CURLOPT_HTTPHEADER - assumed 'CURLOPT_HTTPHEADER' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 89
PHP Notice:  Use of undefined constant CURLOPT_HTTPHEADER - assumed 'CURLOPT_HTTPHEADER' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 93
PHP Notice:  Use of undefined constant CURLOPT_POST - assumed 'CURLOPT_POST' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 106
PHP Notice:  Use of undefined constant CURLOPT_POSTFIELDS - assumed 'CURLOPT_POSTFIELDS' in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 107
PHP Fatal error:  Call to undefined function Twilio\Http\curl_init() in /var/www/twilio/twilio-php-master/Twilio/Http/CurlClient.php on line 24


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Send SMS from parsed file</title>
</head>
<body>
<?php
ini_set("max_execution_time", 0);
$lines=array();
$fp=fopen('twilio_ready.csv', 'r');
while (!feof($fp)) {
    $line=fgets($fp);
    //Add +1 to the number
    $line='+1'.$line;
    //add to array
    $lines[]=$line;
}
fclose($fp);
unset($lines[count($lines)-1]);
$people =  array_flip($lines);

require_once __DIR__ . '/../twilio-php-master/Twilio/autoload.php'; // Loads the library
use Twilio\Twiml;
$servername = "localhost";
$username = "root";
$password = "lcrl62pk";
$dbname = "twilio";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);


use Twilio\Rest\Client;


    $AccountSid = "Something here";
    $AuthToken = "something here";

    // Step 3: instantiate a new Twilio Rest Client
    $client = new Client($AccountSid, $AuthToken);

    foreach ($people as $number => $name) {
                try {
                        $sms = $client->account->messages->create(

                                // the number we are sending to - Any phone number
                                $number,

                                array(
                                        // Step 6: Change the 'From' number below to be a valid Twilio number
                                        // that you've purchased
                                        'from' => "+1844444444",

                                        // the sms body
                                        'body' => "hey there"
                                )
                        );

                        // Display a confirmation message on the screen
                        echo "<font color='green'>Sent message to $name at phone number: $number.</font>"."<br />";
                } catch (Exception $e) {
                        echo "<font color='red'>Couldn't send message to $name at phone number: $number.</font>"."<br />";
                        //add them to black list database!
                }
    }



$conn->close();
print 'DONE!';
?>
</body>
</html>
Hussam Hallak
  • 303
  • 4
  • 21

3 Answers3

6

sudo apt-get install php5-curl

restart the server:

sudo service apache2 restart

Hussam Hallak
  • 303
  • 4
  • 21
  • Depending on your php version and web server version, use the following command. sudo apt install php70-curl AND sudo apachectl restart OR sudo nginx -s reload on Ubuntu server. – Alvin Chettiar Oct 09 '17 at 18:32
  • 1
    The package is just php-curl, eg sudo apt-get install php-curl. This will then install the correct version for your system, eg with the command above: 'The following NEW packages will be installed: php-curl php7.2-curl' – Anthony Feb 14 '18 at 01:28
  • That saved me! That you so much! – Emmet Arries Aug 31 '18 at 23:46
3

Install php7.0-curl

sudo apt-get install php7.0-curl

and then restart the server:

sudo service apache2 restart
Fabian N.
  • 3,807
  • 2
  • 23
  • 46
0

N.B. First of all, you need to install php curl Before installing it you must ensure which version of php you are using and you need to install the same version for php curl.

  • Install php curl
php --version
// PHP 8.1.14
sudo apt-get install php8.1-curl
  • Do not forget to restart apache server
sudo systemctl restart apache2
Md Shayon
  • 79
  • 5