What we are going to be covering in this tutorial

This tutorial will show you how you can set up a PHP contact form on your web site which will send an SMS message, in this case we will make the contact form send you the information passed by the form through an SMS message.

What you will need

Web server (Linux/Windows) with PHP and cURL enabled.
Text editor (For example Notepad++)
Gateway API (We are going to be using SourceSMS)

Lets get started

First of we need to create our visual form which we shall name contact.htm.

Within this file include the following;

<font size="5" face="arial" color="black">
Contact Form

<form name="contactform" method="post" action="send.php">
<table width="450px">
<td valign="top">
  <label for="first_name">First Name *</label>
<td valign="top">
  <input  type="text" name="first_name" maxlength="50" size="30">

<td valign="top"">
  <label for="last_name">Last Name *</label>
<td valign="top">
  <input  type="text" name="last_name" maxlength="50" size="30">
<td valign="top">
  <label for="email">Email Address *</label>
<td valign="top">
  <input  type="text" name="email" maxlength="80" size="30">

<td valign="top">
  <label for="telephone">Telephone Number</label>
<td valign="top">
  <input  type="text" name="telephone" maxlength="30" size="30">
<td valign="top">
  <label for="message">Message *</label>
<td valign="top">
  <textarea  name="message" maxlength="640" cols="25" rows="6"></textarea>

<td colspan="2" style="text-align:center">
  <input type="submit" value="Submit">  

This basically creates the form which sends the POST information to send.php, so lets go ahead and create the send.php file;

For this we need to add the SMS gateway API, as we are going to be using you will need to sign up at SourceSMS.

Once you have got your API account information we need to add their developer API into our code which is;


  $message = $_POST['message'];
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $email = $_POST['email'];
  $telephone = $_POST['telephone'];

$message = "$first_name $last_name $email $message";

// Data for text message. This is the text message data.
$from = "FROM"; // This is who the message appears to be from.
$to = "777000000"; //A single number or a comma-seperated list of numbers
// $message = "This is a test message from the PHP API script"; //160 chars or less
$username = "Your SourceSMS username"; // insert your username
$pword = "Your SourceSMS password"; //Your developer API password
$hash = "RjK=H4kL"; //Do not change
$formCountry = "44"; //Change this to the appropriate country code (default UK)
$sourceinfo = "1"; //Display POST info

//extract data from the post

//set POST variables
$url = 'http://sourcesms.com/api/api-function.php';
$fields = array(

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data

//execute post
$result = curl_exec($ch);

//close connection


You will need to insert your own mobile/cell phone number for the information to be sent to you, ensure you set the "$formCountry" as the international code for your country, the default is for the UK which is "44",

Edited by diafol: fixed formatting

5 Years
Discussion Span
Last Post by Mohammad_30

Could you please help with a simpler "send SMS" for my objective?

.... sending SMS from (Android) mobile using <a href.....

My objective is to send an SMS "receipt" from an Agent's mobile (viewing our web page) instantly to the "payer" to acknowledge receipt of a (small) cash payment .... using the bundled SMS package wih the Agent's phone contarct ... not an external SMS service.

I'm hoping to do this from our website (which the Agent will be viewing at the time of transaction) rather than a dedicated App, if possible.

I have searched everywhere for a simple solution to this and successfully used the following as a prelimanry test

<p><a href="sms:7777777777777?body=SMARTiPAY. £5 received, thank you. ">Send SMS welcome message to new member ></a></p>

.. but what I actually need now is a means of replacing both the "number" and "content" with variables generated from a form on the page .... input fields "mobilenum" and "message" (or other variables if spec needs to be different?)

This is the first time I have used a forum, so I hope I'm not abusing any etiquette or people's kindness.

Thank you


I have followed your tutorial but I am getting this error message after clicking on the submit button: 403 Forbidden nginx

my API password : N6zqrdaY2BgaDPIye8Q2Eb4LJ

Any idea on what it means?


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.