如何使用PHP CURL函数发送短信 [英] How to send SMS using PHP CURL function
问题描述
我在网站上拥有一个帐户,可以通过该帐户向手机发送短信。为此,我首先需要使用我的ID和密码登录,然后显示一个页面,在该页面中输入收件人的手机号码,然后输入我的信息,最后按一下按钮以发送该信息。
I have an account in a website by which I can send sms to mobile phones. In order to do that at first I need to log in using my id and password and then a page shows up where I put the recipient's mobile number and then my message and finally hit the button to send the message.
现在我的一位朋友告诉我,我可以使用PHP Curl函数通过该网站从自己的应用程序发送短信。我之前对CURL函数没有任何想法,所以我用它搜索了一下,但我不知道该怎么做。我已经检查了登录页面的HTML代码以及可以从该页面发送该网站的短信的页面,并将其张贴在下面。
Now one of my friends told me that I can send sms from my own application through this website using PHP Curl function. I didn't have any prior idea about CURL function so I googled it but I couldn't figure out how to do this. I have checked the HTML code of the login page and the page from where I can send the sms of that website and I am posting it below.
请您显示一下我如何使用CURL函数或任何其他方式发送短信..通过此网站。.
Would you please kindly show me how to send sms using CURL function or any other way.. through this website..
在此先感谢:)
Form1
<form name="form" action="/websms/index.php" method="POST">
<input type="hidden" name="HTMLForm_formname" value="form">
<table align="center" size="300" border="0" class="list">
<tr class="r1">
<th colspan="3" class="left">
<label id="label_login_title" for="login_title" class="HTMLForm-label">User Login</label>
</th>
</tr>
<tr>
<td align="right" valign="top">
<label id="label_mobile_no" for="mobile_no" class="HTMLForm-label">Mobile Number</label>
</td>
<td>
<input type="text" id="mobile_no" name="mobile_no" size="20" maxlength="11" value="" onkeypress="return checkNumberOnly(event)" class="HTMLForm-text">
</td>
</tr>
<tr>
<td align="right" valign="top">
<label id="label_password" for="password" class="HTMLForm-label">Password</label>
</td>
<td>
<input type="password" id="password" name="password" value="" class="HTMLForm-password" size="20">
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" id="submit" name="submit" value="Login" class="button_all_action">
<input type="hidden" id="submit_login" name="submit_login" value="1">
</td>
</tr>
</table>
</form>
第二种形式
<form name="form" action="javascript:get(document.getElementById('form'));" method="POST">
<input type="hidden" name="HTMLForm_formname" value="form">
<table align="center" size="450" border="0" class="list">
<tr class="r2">
<th class="left">
<label id="label_send_to_no" for="send_to_no" class="HTMLForm-label">To</label>
</th>
<td class="left">
<textarea id="send_to_no" name="send_to_no" class="HTMLForm-textarea" onkeypress="checkValidGPNumner(document.form.send_to_no)" onchange="checkValidGPNumner(document.form.send_to_no)" onkeyup="checkValidGPNumner(document.form.send_to_no)" wrap="soft" style="width:250px;height:50px"></textarea>
</td>
</tr>
<tr class="r1">
<th class="left">
<label id="label_message" for="message" class="HTMLForm-label">Message</label>
</th>
<td class="left">
<textarea id="message" name="message" class="HTMLForm-textarea" onkeypress="textCounter(document.form.message,document.form.counter_message,160)" onchange="textCounter(document.form.message,document.form.counter_message,160)" onkeyup="textCounter(document.form.message,document.form.counter_message,160)" wrap="soft" style="width:250px;height:130px"></textarea>
<input type="text" id="counter_message" name="counter_message" size="5" value="" readonly="" class="HTMLForm-text"> <label id="label_char_remain" for="char_remain" class="HTMLForm-label">Character remained</label>
</td>
</tr>
<tr class="r2">
<td colspan="2" class="center">
<input type="submit" id="submit" name="submit" value="Send" class="button_all_action">
<input type="hidden" id="mid" name="mid" value="1">
<input type="hidden" id="submit_sms" name="submit_sms" value="1">
</td>
</tr>
</table>
</form>
推荐答案
这是使用Twilio的解决方案。
This is a solution using Twilio.
首先,您必须下载用于PHP的twilio库:
https://github.com/twilio/twilio-php/downloads
First of all you have to download the twilio library for PHP: https://github.com/twilio/twilio-php/downloads
然后将服务文件夹复制到服务器中并放入
Then copy the Services folder in your Server and take in mind the location.
现在,您必须创建一个类似于以下程序的简单程序,(这是一个简单的php sms发件人的示例):
Now you have to create a simple program like the one below, (this is an example an easy php sms sender):
<?php //lets say that the name of this php is smsSender.php
$contactname = $_POST['name'];
$contactphone = $_POST['mobile_no'];
$message = $_POST['message'];
require 'Services/Twilio.php';//<<<<<<<<<HERE! make sure the path is ok.
$AccountSid = "AXXXXXX"; // this numbers you can find it in your twilio dashboard
$AuthToken = "TXXXXXXXXX";// also this number .
$client = new Services_Twilio($AccountSid, $AuthToken);
$people = array(
//"4566789903" => "Curious George",
$contactphone => $contactname,
);
foreach ($people as $number => $name) {
$sms = $client->account->sms_messages->create("7035960031",$number,
$message);
echo "Sent message to $name";
}
?>
因此,您需要在表单中更改以下操作:
So you will need to change in your forms the action like this:
<form name="form" action="smsSender.php" method="POST">
注意:如果您使用的是试用帐户,则只能在中发送已验证的号码您的帐户,但是如果您注册一个电话号码(每月1美元),则可以发送到任何电话号码,而不会发送沙盒消息)。
Note: if you are using a trial account, you will be only able to send to verified numbers in your account, but if you register a phone number (1USD/month) then you can send to any number and without the sandbox message).
重要提示:卷曲库必须是安装在php服务器中,如果您使用自己的服务器,可以在UBUNTU中说,该命令将安装这些库:
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
IMPORTANT: Curl library must be installed in the php server, if you are using your own server, lets say in UBUNTU, this command will install those libraries: sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
这篇关于如何使用PHP CURL函数发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!