Introduction:
Now a days web developers are using SMS for verification purpose, because they think it is the most trusted method for verification. We know that SMS is not free, but some companies are providing free SMS credit, by using this free credits we can send free SMS. Companies like Way2sms are not providing any official API to send SMS but some other companies will give you SMS API with Free Credits. Today I am going to write a tutorial that will helps you to integrate a website or localhost PHP page with SMS API and send SMS through it.
How Integrate SMS API With Your Website or Localhost PHP Page:
It is very easy to integrate SMS API with your PHP Page. Before you start you have to create a free Account with : Fast2Sms. After you create A/c with the website, Follow the steps that give below.
- Log-in to the Dashboard of Free2Sms A/c and go to API Section and Grab your Access Token from them.
- Grab your free Access token from the dashboard by click the "Token ID" and download the ready made PHP script from the below link address.
- Download Latest Ready Made API Integrated PHP Script.
- Upload the script to your web server using FTP. If you are using localhost with Xampp then move the file to Htdocs folder.
- Now open the "sendsms.php" Page and edit your "Token ID" by replacing the "Your Token Here" Text.
<?php $token = 'Your Token Here'; $mobile = mysql_real_escape_string($_POST['phone']); $msg = mysql_real_escape_string($_POST['message']); $site = 'Your Site Address Here'; $url = "http://api.fast2sms.com/sms.php?token=".$token."&mob=".$mobile."&mess=".$msg."&sender=".$site."&route=0"; $homepage = file_get_contents($url); if($homepage) { echo "Message Send Compleated..."; } else{ echo "Something Went Wrong..."; } ?>
- The above code is the primary code. After user click the submit button, The form will post the phone number and message to the sendsms.php. The $mobile and $msg will receive it and pass the value to the the API.
- On the above code, you have to change the $token value to your Token and $site value to your site address.
- Now open the index.php via your browser and start to send sms.
- You are done.
No comments:
Post a Comment