Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.
Moderator: General Moderators
nlks
Forum Newbie
Posts: 2 Joined: Mon May 17, 2004 8:59 am
Post
by nlks » Mon May 17, 2004 11:07 am
phice wrote: I've whipped up a small php file that will allow the user to send text messages of 130 chars or less, to the desired phone number, and desired service.
Source:
Code: Select all
<html>
<body>
<font style=font-family:Verdana;font-size:12px;color:000000;>
<?
if ($_POST["action"] == "send") {
// Sort through services
switch($_POST["service"]) {
case 'att':
$service = "mobile.att.net";
break;
case 'cingular':
$service = "mycingular.com";
break;
case 'nextel':
$service = "messaging.nextel.com";
break;
case 'qwest':
$service = "qwestp.com";
break;
case 'sprintpcs':
$service = "messaging.sprintpcs.com";
break;
case 't-mobile':
$service = "tmomail.net";
break;
case 'verizon':
$service = "vtext.com";
break;
case 'voicestream':
$service = "voicestream.net";
break;
}
// Trim up a few variables
$number = str_replace("(", "", $_POST["number"]);
$number = str_replace(")", "", $number);
$number = str_replace("-", "", $number);
$number = str_replace(" ", "", $number);
$number = eregi_replace("^[a-zA-Z]$", "", $number);
$smsto = $number . "@" . $service;
if (strlen($message) > 130) {
echo "Message is too long. Try keeping the message under/exactly 130 characters.<p>\n\n";
} else {
mail($smsto, $subject, $message, "From: The xSMS service") or die("Unable to send your message. Please try again later.");
// Record information into MySQL Database
$time = time();
@mysql_connect("localhost", "user", "pass");
@mysql_select_db("php");
mysql_query("INSERT INTO sms_messages (`number`,`service`,`email`,`message`,`time`) VALUES ('{$_POST["number"]}','{$_POST["service"]}','$smsto','{$_POST["message"]}','$time')");
echo "Your message has been sent.<p>\n\n";
}
}
?>
<form method="POST" align=center action=<? echo $PHP_SELF; ?>>
<input type=hidden name=action value=send>
<table border=0 cellspacing=2 cellpadding=0 style=font-family:Verdana;font-size:12px;color:000000;>
<tr><td><b>Message:</b></td><td valign="top"><textarea name=message rows=5 cols=18 wrap=no style=font-family:Verdana;font-size:12px;color:000000;></textarea></td></tr>
<tr><td><b>Number:</b></td><td valign="top" align=left><input type="text" name=number style=font-family:Verdana;font-size:12px;color:000000; size=19></td></tr>
<tr><td><b>Service:</b></td><td valign="top" align=left><select name=service style=font-family:Verdana;font-size:12px;color:000000;><option value="att">AT&T Wireless<option value="cingular">Cingular<option value="nextel">Nextel<option value="qwest">Qwest Wireless<option value="sprintpcs">Sprint PCS<option value="t-mobile">T-Mobile<option value="verizon">Verizon<option value="voicestream">VoiceStream</select></td></tr>
<tr><td valign="top" align=left></td><td valign="top" align=left><INPUT TYPE="submit" width=84 height=15 border=0 value="Send Message" style=font-family:Verdana;font-size:12px;color:000000;></td></tr>
</table>
</form>
</font>
</body>
</html>
Edit: Updated service list
Oh, firstly, thx bech for answering me,
me now wif the PHP installed,
I follow his source code,
but still face problem:
1.Notice: Undefined index: action in c:\inetpub\wwwroot\a.php on line 6
2.Notice: Undefined variable: PHP_SELF in c:\inetpub\wwwroot\a.php on line 54
any ideas??
phice
Moderator
Posts: 1416 Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:
Post
by phice » Mon May 17, 2004 8:14 pm
I've fixed the code to coinside with the structure that I program with now. Tell me if you keep getting any errors.
Code: Select all
<?php
echo "<html>\n";
echo "<body>\n";
echo "<font style="font: 12px Verdana; color: #000000;">\n";
if ($_POST["action"] == "send")
{
// Sort through services
switch($_POST["service"])
{
case 'att': $service = "mobile.att.net"; break;
case 'cingular': $service = "mycingular.com"; break;
case 'nextel': $service = "messaging.nextel.com"; break;
case 'qwest': $service = "qwestp.com"; break;
case 'sprintpcs': $service = "messaging.sprintpcs.com"; break;
case 't-mobile': $service = "tmomail.net"; break;
case 'verizon': $service = "vtext.com"; break;
case 'voicestream': $service = "voicestream.net"; break;
}
// Trim up a few variables
$number = str_replace("(", "", $_POST["number"]);
$number = str_replace(")", "", $number);
$number = str_replace("-", "", $number);
$number = str_replace(" ", "", $number);
$number = eregi_replace("^[a-zA-Z]$", "", $number);
$smsto = $number . "@" . $service;
if (strlen($message) > 130) {
echo "Message is too long. Try keeping the message under/exactly 130 characters.<p>\n\n";
}
else
{
@mail($smsto, $subject, $message)
or die("Unable to send your message. You might have to enable your server to send mail using mail() in your php.ini file.");
echo "Your message has been sent.<p>\n\n";
}
}
echo "<form method="POST" action="" . $_SERVER['PHP_SELF'] . "">\n";
echo "<input type="hidden" name="action" value="send">\n";
echo "<table border="0" cellspacing="2" cellpadding="0" style="font: 12px Verdana; color: #000000;">\n";
echo " <tr>\n";
echo " <td><b>Message:</b></td>\n";
echo " <td valign="top"><textarea name="message" rows="5" cols="18" wrap="no" style="font: 12px Verdana; color: #000000;"></textarea></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td><b>Number:</b></td>\n";
echo " <td valign="top" align="left"><input type="text" name="number" style="font: 12px Verdana; color: #000000;"></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td><b>Service:</b></td>\n";
echo " <td valign="top" align="left">\n";
// List out the services
echo " <select name="service" style="font: 12px Verdana; color: #000000;">\n";
echo " <option value="att">AT&T Wireless\n";
echo " <option value="cingular">Cingular\n";
echo " <option value="nextel">Nextel\n";
echo " <option value="qwest">Qwest Wireless\n";
echo " <option value="sprintpcs">Sprint PCS\n";
echo " <option value="t-mobile">T-Mobile\n";
echo " <option value="verizon">Verizon\n";
echo " <option value="voicestream">VoiceStream\n";
echo " </select>\n";
echo " </td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td valign="top" align="left"> </td>\n";
echo " <td valign="top" align="left">\n";
echo " <INPUT TYPE="submit" width="84" height="15" border="0" value="Send Message" style="font: 12px Verdana; color: #000000;">\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "</form>\n";
echo "</font>\n";
echo "</body>\n";
echo "</html>";
?>
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Sat Jul 31, 2004 2:25 am
Sure you have the right service provider address?
Sure you added your area code before your number?
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Sat Jul 31, 2004 2:35 am
You're provider might require additional mail headers to be defined for spam filtration reasons.
nigma
DevNet Resident
Posts: 1094 Joined: Sat Jan 25, 2003 1:49 am
Post
by nigma » Tue Aug 03, 2004 9:34 pm
Some forum members might find it useful if they could get a sms message whenever they're topic was replied to. I don't have a cell so wouldn't help me, but if I had one, that would be awesome.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 04, 2004 12:09 am
unless you get charged per sms.. yikes
nigma
DevNet Resident
Posts: 1094 Joined: Sat Jan 25, 2003 1:49 am
Post
by nigma » Wed Aug 04, 2004 10:40 am
Yea, in that case probably not
myleow
Forum Contributor
Posts: 194 Joined: Mon Jun 21, 2004 7:05 pm
Location: California
Post
by myleow » Sat Sep 11, 2004 1:59 pm
There is this one site, i came across that has phone number that shows which carrier from around the world.
THe only thing is in U.S. with the Number Portability just implemented, the site still has my number as AT&T though i switch to T-Mobile and ported my number too.
Anyway, i should be useful. I think numberplan.com is the place that sells the DB listing for all Telecom number assignment.
http://www.fonefinder.net is the site i am talking about.
I am currently wondering how to send vCard through SMS to a Cell Phone. I tried sending it as email with the vCard encoding but it just shows up as text.
Anyone know about this? Sites like
http://www.vazu.com provides suck service but its USD$0.30 a contact.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Sat Sep 11, 2004 2:56 pm
myleow wrote:
I am currently wondering how to send vCard through SMS to a Cell Phone. I tried sending it as email with the vCard encoding but it just shows up as text.
I doubt it can be done through email if the gate in question does not support such a functionality. It's possible to send vCard messages via gsm phone connected to the server as the modem though (check out cpan module GSM-SMS-0.162)
bla5e
Forum Contributor
Posts: 234 Joined: Tue May 25, 2004 4:28 pm
Post
by bla5e » Mon Sep 13, 2004 8:13 pm
wait does this work on my PERSONAL computer for FREE if i have php installed?
myleow
Forum Contributor
Posts: 194 Joined: Mon Jun 21, 2004 7:05 pm
Location: California
Post
by myleow » Fri Oct 01, 2004 4:35 pm
The next best thing to finding a FREE sms sending provider is to find one that is supported by advertising.
Unfortunately, the majority of Free SMS sites only send Text based SMS. I require one that allow Binary encoded SMS, so i can encode my own messages. eg. vCard, vCal, OTA settings as well as normal text messages.
Regards
Mian
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Fri Oct 01, 2004 9:17 pm
feyd wrote: unless you get charged per sms.. yikes
heh
Most providers offer a few thousand free incoming messages per month, and then they charge you per outgoing message ($0.10-$0.20). Well that's how it is over here in western Canada.
That's an interesting phpBB mod idea indeed. I might incorporate something similar in an OOP-based BB system I'm developing.
Right now it's in a primative stage so it hardly does anything besides BBcode, emoticons, and a moderating system.
bla5e
Forum Contributor
Posts: 234 Joined: Tue May 25, 2004 4:28 pm
Post
by bla5e » Sat Oct 02, 2004 12:02 am
how does AOL work theres? Where it has 1 number, but u can reply to it and it still goes to the correct SN