| |
 |
| |
PHP Examples to Send SMS, Receive SMS. |
 |
| Introduction |
 |
This tutorial demostrates how it is possible to write PHP scripts/applications to send and receive SMS using VisualGSM Enterprise Server.
We shall go through 2 methods which you can use to send SMS through VisualGSM Enterprise:
1). Execute an SQL statement to insert the new message into VisualGSM LOGLOG table.
2). Issue an HTTP GET to VisualGSM Enterprise CSEND web API.
VisualGSM Enterprise can forward received SMS messages to your PHP script via HTTP GET.
Note:- For complete API parameters, please refer to the VisualGSM Enterprise API Guide.
|
 |
| |
| Software Requirement |
 |
1). VisualGSM Enterprise Server (SMS Gateway)
2). PHP 4 and Apache 1.2 (you may use higher versions)
3). Sample PHP scripts |
 |
| |
| Procedure |
 |
Example 1:- Creating a PHP script to send SMS by executing an SQL statement to insert the new message into VisualGSM LOGLOG table. |
 |
1. Install VisualGSM Enterprise Server.
If you have not installed VisualGSM Enterprise Server, you can download the installers from this link (VisualGSM SMS Gateway Download). Refer to the "Quick Start Checklist" on how to configure VisualGSM Enterprise Server. |
 |
2. PHP/Apache environment.
If you do not have PHP/Apache running on your server, you may download and install VisualGSM Web Service which installs Apache to Port 8000 and creates the Apache root under c:\vgsmweb\www\.
Download the Sample PHP Scripts and extract the folder php-samples and contents to to c:\vgsmweb\www\. |
 |
3. Configure and run PHP script.
There are 3 PHP files, (mssql_insert_db.php,mysql_insert_db.php,oracle_insert_db.php) and 3 corresponding PHP configuration files (mssql_config.php, mysql_config.php, oracle_config.php) in library folder.
Select the configuration file which corresponds to the database you are using for VisualGSM Enterprise and amend the parameter user and password to your setup.
For example, for SQL Server, please configure mssql_config.php:
$dbhost='localhost'; #MSSQL host/ip address.
$dbuser='sa';
$dbpass='password';
$dbname='vgsmdb'; #VisualGSM database in MSSQL, default:VGSMDB
After that, run mssql_insert_db.php from your web browser: http://127.0.0.1:8000/php-samples/mssql_insert_db.php
Note:-Please amend "127.0.0.1:8000" to the address of your Apache/PHP server.
On success, you should get a return message "Successfully Inserted into Database".
Note: If you encounter a database error, please troubleshoot using the following steps:
For MSSQL:
i). Ensure that SQL Server service is running and your $dbhost is correct.
Uncomment extension=php_mssql.dll in php.ini by removing the semi-colon. If you are using VisualGSM Web Service, this is found in c:\vgsmweb\php\php.ini.
Next, copy php_mssql.dll ( c:\vgsmweb\php\extension\ folder or equivalent) to where the php binary is located - c:\vgsmweb\php\.
ii). If step (i) fails to resolve the error, find
ntwdblib.dll
on your MSSQL Server, and copy to where the php binary is located -
c:\vgsmweb\php\ (You may also need to copy the file to c:\Windows\System32 as well). You may also obtain a copy of ntwdblib.dll from the VisualGSM Web Service installer.
Also ensure that your MSSQL accepts TCP/IP connections. Run SVRNETCN.exe in Bin folder of MSSQL. Select TCP/IP and Click on Enable. Click OK and then restart SQL Server.
For Oracle:
i). Uncomment the lines: extension=php_oci8.dll, and extension=php_oracle.dll in php.ini by removing the semi-colon. If you are using VisualGSM Web Service, this is found in c:\vgsmweb\php\php.ini. Next, copy php_mssql.dll ( c:\vgsmweb\php\extension\ folder or equivalent) to where the php binary is located - c:\vgsmweb\php\.
Next, copy php_oci8.dll and php_oracle.dll ( c:\vgsmweb\php\extension\ folder or equivalent) to where the php binary is located - c:\vgsmweb\php\.
|
 |
4. Start VisualGSM Service.
Start VisualGSM Service using the "Start" button on VisualGSM Enterprise Manager.
Note:- If VisualGSM service does not start, refer to the returned message and check your setup. Refer to the next section, troubleshooting.
Proceed with live SMS testing (see Step 3). Refer to the sms server log file for testing details. |
| |
| |
| Example 2:- Using a PHP script to send SMS by issuing an HTTP GET to VisualGSM Enterprise CSEND web API. |
 |
|
1. Install VisualGSM Enterprise Server.
If you have not installed VisualGSM Enterprise Server, you can download the installers from this link (VisualGSM SMS Gateway Download). Refer to the "Quick Start Checklist" on how to configure VisualGSM Enterprise Server.
Note:- For CSEND API to work, you must install and configure IIS (or Apache). Please refer to the "Readme" and "QuickStart Checklist" files in your VisualGSM Enterprise installer download. |
 |
2. PHP/Apache environment.
If you do not have PHP/Apache running on your server, you may download and install VisualGSM Web Service which installs Apache to Port 8000 and creates the Apache root under c:\vgsmweb\www\.
Download the Sample PHP Scripts and extract the folder php-samples and contents to to c:\vgsmweb\www\. |
   |
|
3. Open sendsms.php from your browser.
Open sendsms.php using an editor or Notepad, and change the value of $url string to the URL of CSEND API (csend.exe or csend.dll) on your VisualGSM Enterprise Server.
For example:
$url="http://127.0.0.1/cgi-bin/csend.exe";
After that, open sendsms.php from your browser.
Note:- If you encounter an error, please check if you have configured the permissions on your IIS (refer to "QuickStart Checklist").
|
 |
4. Start VisualGSM Service.
Start VisualGSM Service using the "Start" button on VisualGSM Enterprise Manager.
Note:- If VisualGSM service does not start, refer to the returned message and check your setup. Refer to the next section, troubleshooting.
Proceed with live SMS testing (see Step 3). Refer to the sms server log file for testing details. |
| |
| |
| Example 3:- Setting up VisualGSM Enterprise to forward received SMS messages to your PHP application via HTTP GET. |
 |
|
1. Install VisualGSM Enterprise Server.
If you have not installed VisualGSM Enterprise Server, you can download the installers from this link (VisualGSM SMS Gateway Download). Refer to the "Quick Start Checklist" on how to configure VisualGSM Enterprise Server. |
 |
2. PHP/Apache environment.
If you do not have PHP/Apache running on your server, you may download and install VisualGSM Web Service which installs Apache to port 8000 and creates the Apache root under c:\vgsmweb\www\.
Download the Sample PHP Scripts and extract the folder php-samples and contents to to c:\vgsmweb\www\. |
 |
|
3. Following that, create the HTTP type keyword to forward received SMSes to sms2php.php.
Run VisualGSM Enterprise Manager, and click on "Keyword" tab.
Scroll through the table and select the keyword with the name "NOKEYWORD". Click on "Edit ", change the Type to "HTTP URL" (refer to the below screen capture for details).
If you are using VisualGSM Web Service, please set URL as:
Note:-Please amend "127.0.0.1:8000" to the address of your PHP server.
Set Parameter as:
Click on the TEST button to simulate the Keyword Action.
|
 |
 |
 |
 |
|
5. Start VisualGSM Service and test your new setup.
Start VisualGSM Service using the "Start" button on VisualGSM Enterprise Manager.
Send some SMSes to your VisualGSM Enterprise Server - you should receive a response SMS similar to the following example:
PhoneNumber:+6590601300
Keyword:Hello
Message:World
Modem Port:COM4
COMMMETHOD:
SMSC Number:
DB Seqno:1255491
Sendfrom:
Note:- If VisualGSM service does not start, refer to the returned message and check your setup. Refer to the next section, troubleshooting.
Proceed with live SMS testing (see Step 3). Refer to the sms server log file for testing details. |
 |
6. Redirecting received SMS to another recipient or group of users.
If you need to redirect received SMS to another recipient or group of users, please amend sms2php.php to the following (Note: The following example is for MySQL).
To use, send the following message to the SMS Gateway:
[Recipient-Group] Hi, how are you!
Replace [Recipient-Group] with your recipient/group name.
<?php
error_reporting(E_ALL|E_STRICT);
echo "Thank you, your message has been forwarded to Group:". $_GET['KEYWORD'];
include 'library/mysql_config.php'; #### Amend mysql_config.php as required!
$destination=$_GET['KEYWORD'];
$content=$_GET['M']."- SMS forwarding service from Visualtron";
$content=substr($content,0,160); #limits the redirected SMS to a maximum of 1 SMS length.
$sql="INSERT INTO LOGLOG (DESTINATION,CONTENT) VALUES('" . $destination . "','" . $content . "');";
mysql_query($sql,$conn) or die("Error in Execution Query:" . mysql_error());
echo "Successfully Inserted into Database";
?> |
|
 |
|
|
 |
| |
| Troubleshooting |
 |
If you are facing any issues, please refer to the sms_server_log.txt file for logging details.
Default path for sms server log:
c:\Program Files\Visualtron Software Corporation\VisualGSM\vgsmlog\sms_server_log.txt
If you have any questions or comments, you may post on the support forum for this tutorial - click here. |
| |
 |
| |
| Relevant links |
Java Examples to Send SMS, Receive SMS.
ASP.NET Examples to Send SMS, Receive SMS.
Send SMS from Outlook (Via Exchange Server or Lotus Notes using POP3)
Send an SMS via email Demo
Build an SMS Directory Bot in just 4 hrs (including testing)
How to configure Microsoft Exchange SMTP Connector to send SMS
VisualGSM Enterprise API Guide |
| |
| |
| |