I handle a website where RSFormPro is used to receive online bookings, and I thought it would be great to receive an SMS message on the cellphone whenever a form was submitted. After a little search completed with RSFormPro technical team advice I have it working. Here is waht I did and eant to share with people here who might be interested on doing the same.
To have SMS messages sent, there is the need to have a Clickatell account, that provides gateway services to send SMS messages to a lot of countries - visit
www.clickatell.com). Follow the steps below:
Step 1 - Register for a Clickatell account
If you do not already have a Clickatell account, you need to register for one. Otherwise proceed to Step 2.
- Go to
www.clickatell.com/products/sms_gateway.php, and choose the appropriate API subproduct (connection method) you wish to use (Clickatell Central - API)
- Click on the registration link.
- Fill out the registration form.
After successfully submitting the form you will automatically be logged into your new account and taken to a page where you can add your chosen API connection.
Step 2 - Add/create a registered API connection (sub-product)
If you are not already logged into your account, then you must do so at
www.clickatell.com/login.php
- Select \"Manage my Products\" from the top menu.
- Select the API connection type you wish to use (HTTP API) from the drop down menu ('Add Connection' )
- Complete the form. You may enter the locked IP(the IP of your server), this making shure messages will only be accepted if originary from your server's IP address: set Callback to HTTP POST. And you need to set the IP callback to your website address, like
www.yoursite.com/. The result of messages sent, successful or not is sent to this address.
Theoretically there would be a display there, of the message sending result. In practice this way it does not work, i.e. no message is displayed anywhere, which is exactly what I wanted; there is no interruption of the website flow.
If you register more than one API connection, the description name you enter for each must be unique - you cannot have multiple APIs with the same name.
After successfully submitting the form, your authentication details will be displayed, including each connection's unique API ID (api_id). These authentication details are required when connecting to the Clickatell gateway to send a message.
Step 3 - Insert a script on your form
Go to the RSFormPro and select your form(s), and insert under 'Scripts -> script called on form process, the following script:
$user = "xxxxxxxxxxxx";
$password = "xxxxxxxxx";
$api_id = "xxxxxx";
$baseurl ="
api.clickatell.com";
$text = urlencode("Text of your message here" );
$to = "123123456789";
// auth call
$url = "$baseurl/http/auth?user=$user&password=$password&api_id=$api_id";
// do auth call
$ret = file($url);
// split our response. return string is on first line of the data returned
$sess = split(":",$ret[0]);
if ($sess[0] == "OK" ) {
$sess_id = trim($sess[1]); // remove any whitespace
$url = "$baseurl/http/sendmsg?session_id=$sess_id&to=$to&text=$text";
// do sendmsg call
$ret = file($url);
$send = split(":",$ret[0]);
if ($send[0] == "ID" )
echo "success
message ID: ". $send[1];
else
echo "send message failed";
} else {
echo "Authentication failure: ". $ret[0];
exit();
}
where user is your clickatell username, followed by your clickatell password and the api_id you defined on step 2. The numbers after $to, are the cellphone numbers to where the SMS has to be sent, where the first digits are the country code followed by the phone number. If there is more than one destination, separate them by commas ("123123456789,123345678123,etc)".
As i mentioned before, the part of the script echoing the sending results (echo, etc) is not shown anywhere (at least using this method), so I didn't bother to find out a way of eliminating those lines.
As text, write anything you would like to be displayed on the SMS message. If you would like to include fields from the form, concatenate them in the message text like this:
$text = urlencode("Message text informing what was filled in at ".${Fieldname_1:value}." as well as ".${Fieldname_2:value}."so anything goes here." );
And that's it! Whenever the form is submitted, you will see the thank you message if you have defined it or whatever sequence you set up, and at the same time a message will be delivered to your cellphone. Easy and chep, Clickatell works on the base of credits, i.e. you book and pay an amount and it will be converted into credits. Then each message is worth a number of credits, 1, 1.5, 2, etc (according to the destination and operator, I think). The minimum value equals 400 credits. Further information about this can be obtained at
www.clickatell.com/downloads/http/Clickatell_HTTP.pdf
Enjoy!