0
votes

I tried to send sms using php with the help of twilio API. But I have occeured fallowing errors when running code.

my code

{require ('./twilio/Services/Twilio.php'); // Loads the library


$accountSid = 'AC****************************';
$authToken  = 'ec****************************'; 
$client = new Services_Twilio($accountSid, $authToken);

$sms = $client->account->sms_messages->create("number", "number", "Jenny please?! I love you <3");

errors

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in C:\wamp\www\Pizza4U\twilio\Services\Twilio\HttpStream.php on line 62

Warning: file_get_contents(): Failed to enable crypto in C:\wamp\www\Pizza4U\twilio\Services\Twilio\HttpStream.php on line 62

Is there a way to fix this. Thank you

1
are you on localhost / wamp server?tonoslfx
ya and I use ngrok tunneling softwareIsuru44
check your settings, if curl is enabled?tonoslfx
How can I do it. thanks for quckly replyIsuru44
i m not familiar with ngrok! you need to find php.ini file. or you can check if its enabled by putting phpInfo(); in your index.phptonoslfx

1 Answers

0
votes

To avoid SSL certificate issues on wampserver localhost whilst testing, make sure that you insert the following line of code:

CURLOPT_SSL_VERIFYPEER => false,

in

twilio/sdk/Twilio/Http/CurlClient.php (from line 113 onwards)

public function options($method, $url, $params = array(), $data = array(),
                        $headers = array(), $user = null, $password = null,
                        $timeout = null) {

    $timeout = is_null($timeout)
        ? self::DEFAULT_TIMEOUT
        : $timeout;
    $options = $this->curlOptions + array(
        CURLOPT_URL => $url,
        CURLOPT_HEADER => true,
        CURLOPT_RETURNTRANSFER => true,
        //added here during localhost wampserver testing to avoid SSL issues
        //CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_INFILESIZE => Null,
        CURLOPT_HTTPHEADER => array(),
        CURLOPT_TIMEOUT => $timeout,
    );

Remove the line once you are in production mode. The server that you are hosted on will I'm sure have the correct bundle of trusted certificates. At least with this setting set to false, your twilio application on localhost will not be checking your localhost for SSL certificates. This avoids having to download the correct certificates and bypasses the issues completely. See pflammer's comment at https://github.com/twilio/twilio-php/issues/203.