0

I'm trying to send a text message on a button click on my webpage. I have a twilio trial account set up and I'm using the php helper library that they have provided.

My php looks like this but with my credentials. The 500 error occurs on the line where create() is called. Any help would be greatly appreciated.

I am using php 7 and composer.

<?php
// Required if your environment does not handle autoloading
require_once 'vendor/autoload.php';

// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;

try{
    $sid = 'XX';
    $token = 'YY';
    $client = new Client($sid, $token);
    // Use the client to do fun stuff like send text messages!

$sms = $client->messages->create('+15551234567', array('from' => '+15556361234','body' => 'Hey Jenny! Good luck on the bar exam!');
echo $sms;
}catch(Exception $e){
    echo $e->getMessage();
}
?>

Also my ajax call looks like this

$(document).on('click','#textmessage',function(e){
    e.preventDefault()
    data = {}
    $.ajax({
        url:'textmessage.php',
        type:'GET',
        data:data,
        success:function(data){
                console.log(data)
          },
        error: function (request, status, error) {
            console.log(request)
    }

    });  

});

0 Answers0