I followed instructions on this website and I have an error in my sendnotifications.php file, I don't receive the sending confirmation and messages "message sent" and "message not sent" don't display on my screen.
Everything works for the SMS, I receive it on my phone.
Here the PHP file:
<?php
// Required if your environment does not handle autoloading
require __DIR__ . '/Twilio/autoload.php';
// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;
// Your Account SID and Auth Token from twilio.com/console
$sid = ‘MyAccountSID’;
$token = ‘MyToken’;
$client = new Client($sid, $token);
$phone=$_POST["phone"];
// Use the client to do fun stuff like send text messages!
$client->messages->create(
// the number you'd like to send the message to
$phone,
array(
// A Twilio phone number you purchased at twilio.com/console
'from' => ‘MyTwilioNumber’,
// the body of the text message you'd like to send
'body' => « MyMessage »
)
);
// Display a confirmation message on the screen
$sms_check=’OK’; //Use Twilio’s callback here
$return_json = ‘{"sms_sent":"’ . $email_check . ‘"}’;
echo $return_json;
?>
Here my HTML form:
<!doctype html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">// <![CDATA[///////////Javascript
$(function(){
$("#frm").submit(function(e){
e.preventDefault();
$.post("sendnotifications.php", $("#frm").serialize(),
function(data){
if(data.sms_sent == 'OK'){
alert("Message Sent");
} else {
alert("Message Not Sent");
}
}, "json");
});
});
// ]]>
</script>
</head>
<html>
<form id="frm" name="frm">
<input type="hidden" name="ajax" value="1" />
<input type="phone" name="phone" />
<button type="submit">Get Link</button>
<div class="error" style="display: none;"></div>
</form>
</html>
Here the error in Visual Studio Code:
{
"resource": "/Users/Joris/Desktop/Test envoi sms accueil/sendnotifications.php",
"owner": "_generated_diagnostic_collection_name_#0",
"code": "undefined",
"severity": 8,
"message": "syntax error, unexpected '{'",
"startLineNumber": 31,
"startColumn": 1,
"endLineNumber": 31,
"endColumn": 1.7976931348623157e+308
}
Here the error on Chrome:
Uncaught TypeError: Cannot read property 'sms_sent' of null
at Object.success (source.html:10)
at b (jquery.min.js:124)
at XMLHttpRequest.x.onreadystatechange (jquery.min.js:129)
(anonymous) @ source.html:10
b @ jquery.min.js:124
x.onreadystatechange @ jquery.min.js:129
XMLHttpRequest.send (async)
ajax @ jquery.min.js:130
post @ jquery.min.js:122
(anonymous) @ source.html:8
handle @ jquery.min.js:55
o @ jquery.min.js:49