程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php 發送sms實例代碼

php 發送sms實例代碼

編輯:關於PHP編程

<html>
<head>
<title>SMS Web Sender Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<h2>SMS Web Sender DEMO!</h2>

<?php
if ($action != "submit") {
?>

<i>Any username or password you enter here will not be stored
 in any way (although we're not using SSL either)</i>

<p><i>Also, as you can see most of these are UK sites, not all
of them will support international numbers!</i></p>

<form method="post" action="demo.php">
  <table width="600" border="0" cellspacing="0" cellpadding="4">
    <tr>
      <td align="right"><b>Site</b></td>
      <td>
        <select name="site">
          <option value="txtuk.net">txtuk.net (no login)</option>
          <option value="mtnsms_com">mtnsms.com</option>
          <option value="lycos_co_uk">lycos.co.uk</option>
          <option value="excite_co_uk">excite.co.uk</option>
          <option value="uboot_com">uboot.com</option>
          <option value="genie_co_uk">genie.co.uk</option>
        </select>
      </td>
    </tr>
    <tr>
      <td align="right"><b>User</b></td>
      <td>
        <input type="text" name="user">
      </td>
    </tr>
    <tr>
      <td align="right"><b>Password</b></td>
      <td>
        <input type="password" name="pass">
      </td>
    </tr>
    <tr>
      <td valign="top" align="right"><b>Number</b></td>
      <td>
        <input type="text" name="number">
        (eg. +447123123123)</td>
    </tr>
    <tr>
      <td valign="top" align="right"><b>Message</b></td>
      <td>
        <textarea name="message" cols="40" rows="8"></textarea>
      </td>
    </tr>
    <tr>
      <td align="right"><b>Debug</b></td>
      <td>
        <input type="checkbox" name="debug" value="yes">
      </td>
    </tr>
    <tr>
      <td align="right">&nbsp;</td>
      <td>&nbsp; </td>
    </tr>
    <tr>
      <td align="right">&nbsp;</td>
      <td>
    <input type="hidden" name="action" value="submit">
        <input type="submit" name="Submit" value="Send!">
      </td>
    </tr>
  </table>
</form>

<?php

} else {

 // contains the site details
 include("sites.php");

 // contains main class
 include("class.sms_web_sender.php");

 if (empty($number) || empty($site) || empty($message)) {
  die("Make sure number, site and message are not empty");
 }

 if (!empty($debug) && $debug == "yes") {
  $debug = true;
 } else {
  $debug = false;
 }

 // signature bit of text that's required by some
 // sites like MTNSMS.com, you can leave as is
 $signature = "*";

 // create instance of sms web sender the one
 // optional argument will determine if
 // debug is turned on or not
 $sms = new sms_web_sender($debug);

 // add accounts
 // 1st argument: username
 // 2nd argument: password
 // 3rd argument: server
 // 4th argument: weight (this is only useful when
 //               shuffling the logins, the higher
 //               the weight, the more likely it'll
 //               be placed near the top of the list)
 //               default if left blank: 1
 $sms->add_login("$user", "$pass", "$site");

 // add Proxy Server details if required
 // I haven't tested this myself, feature of jm_sms
 //$sms->setProxyServer("proxyserver");
 //$sms->setProxyPort(81);
 //$sms->setProxyUser("proxyusername");
 //$sms->setProxyPass("proxypassword");
 //$sms->setProxy(true);

 // passes the number, signature and message in an array
 $result = $sms->send_sms(array("number"=>$number, "signature"=>$signature, "message"=>$message));

 if ($result) {
  echo "<h2>Sent!</h2>";
 } else {
  echo "<h2>Could not send :(</h2>";
  echo "<p><a href="javascript:history.back()">Go Back</a></p>";
 }

}

?>

</body>
</html>


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved