简体   繁体   中英

Can't send sms using twilio error occured

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

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 .

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