Simple one page script that will send SMS text messages using PHP.
Hope you like it.
| Code: sms_app.php | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <link rel="stylesheet" type="text/css" href="/style.css" /> <title> PHP SMS Message Generator </title> </head> <body> <?php // if the form has NOT been submitted if (!isset($_POST['submit'])) { ?> <div id="container"> <h1>PHP SMS Message Generator</h1> <form id="sms" method="post" action="<?=$_SERVER['PHP_SELF']?>"> <table width="410" align="center"> <tr> <td align="right">From:</td> <td align="left"><input name="from" type="text" id="from" size="30" /></td> </tr> <tr> <td align="right">Recipient's 10 digit #:</td> <td align="left"> <input name="number" type="text" id="number" size="14" maxlength="15"/> @ <select name="carrier" id="carrier"> <option>Select A Carrier</option> <option value="@message.alltel.com">Alltel</option> <option value="@txt.att.net">AT&T</option> <option value="@myboostmobile.com">Boost</option> <option value="@messaging.nextel.com">Nextel</option> <option value="@tmomail.net">T-Mobile</option> <option value="@vtext.com">Verizon Wireless</option> <option value="@vmobl.com">Virgin Mobile</option> </select> </td> </tr> <tr> <td align="right" valign="top">Message:</td> <td align="left"><textarea name="message" cols="40" rows="5" id="message"></textarea></td> </tr> <tr> <td colspan="2" align="center"><input class="button" type="submit" id="submit" name="submit" value="Send Message" /></td> </tr> </table> </form> </div> <?php }// close of if--> the form has NOT been submitted // if the form HAS been submitted else { // make safe variables function function make_safe($variable) { $variable = trim($variable); //if storing in a database --> mysql_real_escape_string(trim($variable)) return $variable; } //make safe needed variables $from = make_safe($_POST['from']); $number = make_safe($_POST['number']); $message = make_safe($_POST['message']); //do not make_safe ---> $carrier $carrier = $_POST['carrier']; //concatenate the number and carrier $sendto = $number.$carrier; //check to see if form has been filled out correctly if ((empty($carrier)) || (empty($sendto)) || (empty($message))) { echo "<div id='container'>An error has occured please try again."; echo "<br />"; echo "<a href='/sms_app.php'>Go back</a></div>"; } else { //SENDS TEXT MESSAGE TO //format like this (example) //mail($PhoneNumber, $Subject, $Message, 'From: ' . $Email); //OR //mail($PhoneNumber, $Subject, $Message); mail($sendto,'SMS',$message,'From:' .$from); // Currently, the subject is set to "SMS", change this is you wish //has been sent successfully echo "<div id='container'>Success!</div>"; echo "<br />"; echo "<a href='/sms_app.php'>Go back</a></div>"; } }// close of else --> the form HAS been submitted //the end ?> </body> </html> |
And the style sheet...
| Code: style.css | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
body { font-family: Arial, Helvetica, Verdana,sans-serif; font-size: 14px; margin:10px 0 0 0; } p { font-size: 14px; font-weight: normal; } h1 { font-size: 22px; font-weight: normal; color: #666; text-align: center; } a:link {color:#666} /* unvisited link */ a:visited {color:#666} /* visited link */ a:hover {color:#808080; text-decoration: none;} /* mouse over link */ a:active {color:#666} /* selected link */ #container { width:430px; margin: 10px auto; padding: 8px; background: #F1F1F1; border:1px solid #BBBBBB; } .button { background: #FFF; border:1px solid #336699; color:#336699; font-size:85%; padding:3px 10px; text-transform:uppercase; } .button:hover, .button:focus { background:#DDD; border:1px solid #000; color:#111; } |
Code Blog
