0

I've got the following php file below. When I run it from the terminal, it works great. However, when I open php file in the browser, I get the following exception:

Fatal error: Uncaught exception 'Twilio\Exceptions\EnvironmentException' with message 'SSL certificate problem: unable to get local issuer certificate' in /Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Http/CurlClient.php:41 Stack trace: #0 /Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Rest/Client.php(208): Twilio\Http\CurlClient->request('POST', 'https://api.twi...', Array, Array, Array, 'AC9fc89840f15b3...', 'd1db324eb375a2e...', NULL) #1 /Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Domain.php(70): Twilio\Rest\Client->request('POST', 'https://api.twi...', Array, Array, Array, NULL, NULL, NULL) #2 /Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Version.php(64): Twilio\Domain->request('POST', '2010-04-01/Acco...', Array, Array, Array, NULL, NULL, NULL) #3 /Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Version.php(216): Twilio\Version->request('POST', '/Accounts/AC9fc...', Array, Array, Array, NULL, NULL, NULL) #4 /Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Rest/Api/V2010/Account/MessageList.php(70): Twili in /Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Http/CurlClient.php on line 41

Here is my code:

    <?php // sendMessageTwilio.php

  require __DIR__ . '/vendor/autoload.php';
  use Twilio\Rest\Client;

    // Your Account SID and Auth Token from twilio.com/console
  $account_sid = 'XXXXXXXXXX';
  $auth_token = 'XXXXXXXXXX';
  // In production, these should be environment variables. E.g.:
  // $auth_token = $_ENV["TWILIO_ACCOUNT_SID"]

    // A Twilio number you own with SMS capabilities
  $twilio_number = "+XXXXXXXX";

  $client = new Client($account_sid, $auth_token);
  $client->messages->create(
      // Where to send a text message (your cell phone?)
      '+XXXXXXXXXXX',
      array(
          'from' => $twilio_number,
          'body' => 'Testing From Website New!'
      )
  );

  $number = $question = '';

  if (isset($_POST['number'])){
    $number = $_POST['number'];
    $out = "Number: $number";
  } 

  if (isset($_POST['question'])){
    $question = $_POST['question'];
    $out = $out."   Question: $question";
  } 

  else $out = "";

  echo <<<_END

<html>
  <head>
    <title>Student Feedback</title>
  </head>
  <body>
    <pre>

      Enter phone number and question
      <b>$out</b>
      <form method="post" action="sendMessageTwilio.php">
        Phone Number: <input type="text" name="number" size="17">
        Question:     <input type="text" name="question" size="17">
                      <input type="submit" value="Send Message">
      </form>
    </pre>
  </body>
</html>
_END;

I'm using the composer to get all the necessary files set up.

Thanks all!

1
  • If I upload it on the server it also works...so seems to be a local issue Commented Jun 13, 2018 at 19:50

1 Answer 1

1

Linux servers usually have the ca_cert.pem in place. Follow these steps to fix your issue

https://support.twilio.com/hc/en-us/articles/235279367-Twilio-PHP-helper-library-SSL-certificate-problem-on-Windows

UPDATE

Here is my code

$http = new Services_Twilio_TinyHttp(
  'https://api.twilio.com',
   array('curlopts' => array(
     CURLOPT_SSL_VERIFYPEER => false,
     CURLOPT_SSL_VERIFYHOST => 2,
   ))
);

$sid = 'ACfb185500bf13ce37c37fd2e13dsdfsdf'; 
$token = '4be5dcdb74e4cbd50d642a56b1fasdf2'; 
$client = new Services_Twilio($sid, $token, "2010-04-01", $http);

$message = $client->account->messages->sendMessage(
    '+441231231231', // From a Twilio number in your account
    '+441231231231,
    'OTP for login is: 1234'
);

You need to set curl options to suppress the SSL verification

CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2,
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Ashik! I should have mentioned that I'm on a Mac. I've followed these instructions: wiki.cacert.org/FAQ/ImportRootCert#Using_the_command_line But I'm still getting the same issue...
Thanks so much for the help!
Thumbs up! For anybody using Laravel framework can disable SSL verification in the Guzzle package

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.