SMS Gateway & Facebook: Get More Opt-in Fans! Part 2
Last week we started prepping our Facebook fan pages to allow fans to sign up for mobile alerts sent through SMS Gateways. Today we’ll input the data into a MySQL database and send an opt-in confirmation SMS.
Right, seeing as there’s quite a lot to get through we’ll kick off straight away with the MySQL database connection.
This is where the details of your Facebook fans will be stored. These details will then also be available at a later stage for SMS messaging via the SMS Gateways. Here’s the code detailing the creation of the database, table and the necessary fields:
mysql> CREATE DATABASE FB_MOB;
mysql> GRANT ALL ON FB_MOB.* TO 'leo'@'localhost' IDENTIFIED BY "password";
mysql> USE FB_MOB;
mysql> CREATE TABLE fb_fan_details
-> (name text,
-> mobnum text
-> );
Seeing as the MySQL query language is almost like English, the above should be pretty self-explanatory. Once you’ve created your database, it’s time to get started on form_arbeit.php – the file that will do all the work. Here’s the content of form_arbeit.php with the relevant documentation:
<?php
//API String
$api_url = 'http://api.clickatell.com/http/sendmsg?';
//Facebook fan name
$name = $_POST['name'];
//Facebook fan mobile number
$mobnum = $_POST['mobnum'];
//Array to be used to send opt-in confirmation message.
$message = array(
//The API ID has to be specified statically
or pulled in from the database.
'to' => $_POST['mobnum'],
'name' => $_POST['name'],
'api_id' => "1234567",
//The username has to be specified statically
or pulled in from the database.
'user' => "username",
//The password has to be specified statically
or pulled in from the database.
'password' => "password",
//The message has to be specified statically or pulled in from the database.
'text' => "Hello $name, your details have been entered on www.somedomain.tld. Confirm your subscription request by replying with YES.",
);
//MySQL host, Username, Password
{$dbcnx = mysql_connect('MySQL_host', 'username', 'password');
//Select the appropriate database
mysql_select_db('FB_MOB');
//MySQL Query
$sql = "INSERT INTO fb_fan_details
SET form_email='$mobnum', form_name='$name'";
//Insert fan’s details into MySQL database
}
if (@mysql_query($sql)) {
echo('<p>You've been added! Confirm your subscription by replying YES
to the message we sent to your phone. Messages charged at normal rates.
Terms & Conditions apply.
Hit 'back' on your browser to return to the previous page.</p>');
} else {
echo('<p>Whoops ' . mysql_error() . '</p>');
}
// Urlencode parameters
foreach ($message as $parameter => $value )
{
$api_url .= $parameter . '=' . urlencode($value) . '&';
}
// Perform an API call. You can also use cURL for this.
$result = file_get_contents($api_url);
echo "API Response: $result\n";
?>
In the code above, you’ll note that the first part deals with variable declaration and the creation of an array. That array is necessary as the information it is passed to the HTTP/S API that is responsible for message transmission through the SMS Gateways.
Now, it is important to note that implementing the above will require you to follow best practice guidelines. Also take into account that the above page will navigate your fan away from Facebook. The code above is for illustrative purposes, but can be modified to fit your own requirements for messaging through SMS Gateways.
Learn more about the various API’s and other SMS solutions – navigate to our SMS Gateways page, now.
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.
One Comment On This Post
[...] Once again, it’s a two-part post, with the first part being The SMS Gateway & Facebook: Get More Opt-in Fans! Part 1 and the second, SMS Gateway & Facebook: Get More Opt-in Fans! Part 2 [...]