PHP

PHP SearchSearch
Author Message
James Madden
Unregistered guest
Posted on Monday, April 05, 2004 - 10:57 pm:   

I am new to PHP and don't quite understand how to use the file sendsms.php. I have a website which allow employees send text message to business contacts when they are overseas. What I want them to do is type the message into a form,click send and the message is sent. When they click the send button in the form should the action of the form be set to sendsms.php? Will this automatically connect to the gateway and send the message? Any help given would be greatly appreciated.
Anonymous
 
Posted on Saturday, April 17, 2004 - 09:23 pm:   

well sounds like i want to se that sendsms.php ... if it is like you say make a form and a button and if button is clicked then <?php include_once="blablabla.php" ?> that should work
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 2338
Registered: 10-2002
Posted on Wednesday, April 21, 2004 - 08:56 pm:   

Keep in mind that the sendsms.php script available on this forum is a script that is specific to the Now SMS/MMS Gateway. You need to be running an installation of the NowSMS gateway somewhere on your network ... and you need to modify the script to include the IP address and port of your NowSMS server.

The sendsms.php script for NowSMS can be found in the following thread:

http://support.nowsms.com/discus/messages/1/867.html

If you wanted to modify this script so that it could be run directly from a web server, that's a relatively simple task (I'm not a PHP expert, and I can do it, so that's why I say it is a simple task ).

Basically, you want to keep the SendSMS function from the other script (just remove some "echo" statements which are really just debug information). And then you want to have your PHP script parse variables that would be passed by a form that has this script as its action.

For example, let's have a script pass variables named "phone" (for the phone number to receive the message) and "text" (for the text of the message). The following script could be the action of such a form:

<?

function SendSMS ($host, $port, $username, $password, $phoneNoRecip, $msgText) {

$fp = fsockopen($host, $port, $errno, $errstr);
if (!$fp) {
echo "errno: $errno \n";
echo "errstr: $errstr\n";
return $result;
}

fwrite($fp, "GET /?Phone=" . rawurlencode($phoneNoRecip) . "&Text=" . rawurlencode($msgText) . " HTTP/1.0\n");
if ($username != "") {
$auth = $username . ":" . $password;
$auth = base64_encode($auth);
fwrite($fp, "Authorization: Basic " . $auth . "\n");
}
fwrite($fp, "\n");

$res = "";

while(!feof($fp)) {
$res .= fread($fp,1);
}
fclose($fp);


return $res;
}


if (isset($_REQUEST['phone'])) {
if (isset($_REQUEST['text'])) {
$x = SendSMS("127.0.0.1", 81, "username", "password", $_REQUEST['phone'], $_REQUEST['text']);
echo $x;
}
else {
echo "ERROR : Message not sent -- Text parameter is missing!\r\n";
}
}
else {
echo "ERROR : Message not sent -- Phone parameter is missing!\r\n";
}

?>

You just need to edit the line that calls the "SendSMS" function so that it points to the IP address and web port of your NowSMS installation ... and the "username" and "password" would be set to an account that is defined under the "SMS Users" configuration in NowSMS.

Hope that helps!

application/octet-streamSendSMSScript.php
SendSMSScript.php (1.1 k)
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 2345
Registered: 10-2002
Posted on Thursday, April 22, 2004 - 04:33 pm:   

Additional information ... here is an example of how you would create a form that called the example sendsmsscript.php script mentioned above.

This is a simple HTML form that allows the user to enter a phone number and message text, and it posts this to the PHP script:

<HTML>
<HEAD><TITLE>Send SMS</TITLE></HEAD>
<BODY>
<form method="post" action="sendsmsscript.php">
<table border="1">
<tr>
<td>Mobile Number:</td>
<td><input type="text" name="phone" size="40"></td>
</tr>
<tr>
<td valign="top">Text Message:</td>
<td><textarea name="text" cols="80" rows="10"></textarea>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Send">
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
James Fleming
Unregistered guest
Posted on Monday, April 26, 2004 - 12:54 am:   

Bryce,
Thanks a million for all your help. Everything is working fine. We have just tested the system from one user connecting in from Montreal to our servers in London. Senior management are very pleased with the system. Somebody from finance will be in contact in the next three - four weeks to discuss purchasing the software.