【问题标题】:Send HTML input to PHP Twilio Script将 HTML 输入发送到 PHP Twilio 脚本
【发布时间】:2014-10-17 23:37:28
【问题描述】:

我是 PHP 和 HTML 表单的新手。我正在尝试将下面的表单数据发送到我的 PHP 脚本 sendms.php 似乎 php 脚本没有从 html 表单获取输入数据。

 <form action="sendsms.php" method="post" >

        <div id="space">Cell:<div><input type="number" name="phone" id="number" ></div></div>
        <div id="space"><div>Message</div><div><input type="text" name="message" id="message">      </div></div>
        <div id="button"><input type="submit" name="send" value="Send" id="button" ></div>

    </form>

这是我的 PHP 文件 sendms.php

<?php

// this line loads the library
require('twilio-php/Services/Twilio.php'); 

$account_sid = 'REMOEVD'; 
$auth_token = 'REMOVED'; 
$client = new Services_Twilio($account_sid, $auth_token); 

$client->account->messages->create(array( 
'To' =>  $_POST['phone'];, 
'From' => "+16194523868", 
'Body' => $_POST['message'];, 

));

【问题讨论】:

  • 您正在使用method="post",但尝试读取$_GET,您需要使用$_REQUEST$_POST

标签: php html twilio


【解决方案1】:

如果您查看表单:

 <form action="sendsms.php" method="post" >

您本质上是posting 表单输入,因此您需要在PHP 中获取$_POST 参数,如下所示:

$client->account->messages->create(array( 
    'To' =>  $_POST['phone'], 
    'From' => "+16194523868", 
    'Body' => $_POST['message']
));

编辑

刚刚注意到您在数组声明中还有一些分号 (;) 仍然会破坏您的代码

【讨论】:

  • 当我知道它是那么小的东西!谢谢 Kypros!
猜你喜欢
  • 1970-01-01
  • 2012-10-04
  • 2015-06-27
  • 2016-06-04
  • 2013-09-04
  • 2019-04-03
  • 1970-01-01
  • 1970-01-01
  • 2017-04-10
相关资源
最近更新 更多