dongliaoqiang8524 2018-05-25 10:07
浏览 140

PHP Twilio API中的语法错误

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
  • 写回答

1条回答 默认 最新

  • douningzhi1991 2018-05-25 10:42
    关注

    The property was 'sms_sent' in HTML and 'sms_check' in PHP

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!