Php Script for Sms Sending

This Php based SMS sending software is designed in such a manner that it can be viewed by any other person. An online SMS package is desired by an internet user to make a quick connection to anyone in the world through the internet. This is the best way to send message to the people who are living in remote areas where there are no communication means. Now a day, people are well aware of this Php script for sms sending that works well with international area code and mobile number service.

With instant messaging growing at a rapid pace worldwide, there is higher demand for businesses and individuals to send bulk text messages to thousands of recipients. Our PHP Script for SMS Sending is built on the latest technologies and allows you to send bulk text messages to multiple destinations at once. It’s integrated with the most popular services such as Google, Yahoo and Verizon Wireless, convenient and reliable, easy to use and user-friendly.

phpsendsms.php

This file is responsible for sending SMS. It collects the form data and configures the authentication key and sender id. The API gateway URL is used to pass the SMS to the gateway. So, there are three entities you basically need from your configuration gateway – Authentication KeySender ID and Gateway URL. The curl_setopt_array() method is used here to transfer multiple options to a CURL.

Make sure to replace the YOUR_AUTH_KEYYOUR_SENDER_ID and YOUR_GATEWAY_URL.

<?php

// Authentication key
$authKey = "YOUR_AUTH_KEY";

// Also add muliple mobile numbers, separated by comma
$phoneNumber = $_POST['phoneno'];

// route4 sender id should be 6 characters long.
$senderId = "YOUR_SENDER_ID";

// Your message to send
$message = urlencode($_POST['smstext']);

// POST parameters
$fields = array(
    "sender_id" => $senderId,
    "message" => $message,
    "language" => "english",
    "route" => "p",
    "numbers" => $phoneNumber,
);

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "YOUR_GATEWAY_URL",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_SSL_VERIFYHOST => 0,
  CURLOPT_SSL_VERIFYPEER => 0,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode($fields),
  CURLOPT_HTTPHEADER => array(
    "authorization: ".$authKey,
    "accept: */*",
    "cache-control: no-cache",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
?>

The above code returns TRUE with message id if all options were successfully set. If an option could not be successfully set, FALSE is immediately returned.

Email to SMS

To learn how to send a message to mobile via email using PHP code, you’ll generally require only two things:

  1. the phone number or unique identifier of the mobile device you want to reach
  2. the wireless network’s domain name (many can be found in this list of email to SMS addresses)

The following convention can be followed for most carriers:

1phoneNumber@domainName.com

phoneNumber is the phone number of the mobile device to send the message to, and domainName.com is the address for the network’s SMS Gateway.

To send an SMS through PHP to Mr. Example, you could simply add 3855550168@vtext.com to any email client, type a message, and hit send. This will send a text message to phone number +1 (385) 555-0168 on the Verizon Wireless Network.

For example, I’ll send a text message to myself using Gmail.

Send SMS Using PHP Tutorial Gmail

When my phone receives the message, it should look like this:

Send SMS to Mobile Using PHP Tutorial Result PHP Send SMS Example

Pretty awesome! It’s fun to think of the possibilities available when sending SMS from a PHP website to mobile.

index.php

Suppose we have the following interface to get the phone number of the recipient and the message text from the website visitors. When the user clicks on the ‘Send Message‘ button, the data will be posted to ‘phpsendsms.php‘ page-

<html>
	<head>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
	</head>
	<body>
	<div class="container">
	<h1>PHP Send SMS</h1>
		<form method="post" action='phpsendsms.php'>
		<div class="form-group">
			<label for="phoneno">Mobile Number</label>
			<input type="text" name="phoneno" class="form-control" placeholder="Enter Phone Number" >
		</div>
		<div class="form-group">
			<label for="exampleFormControlTextarea3">Enter Text Message</label>
			<textarea class="form-control" name="smstext" rows="7"></textarea>
		</div>
		<div class="form-group">
			<input type="submit" name="submit" class="btn btn-primary" value="Send Message">
		</div>	
		</form>
	</div>	
	</body>
</html>

PHP’s mail Function

Let’s take things a step further. Using the SMS Gateway, we can send an SMS to mobile using PHP’s mail function. The mail function has the following signature:

1bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

You can read more about it in the PHP documentation.

  • $to defines the receiver or receivers of the message. Valid examples include:
    • user@example.com
    • user1@example.com, user2@example.com
    • User <user@example.com>
    • User1 <user1@example.com>, User2 <user2@example.com>
  • $subject is rather self-explanatory; it should be a string containing the desired subject. However, SMS messages do not require a subject.
  • $message is the message to be delivered. As mentioned in the PHP manual, “each line should be separated with a LF (\n). Lines should not be larger than 70 characters.”

To replicate the earlier functionality, we could write the following PHP code:

1mail( '3855550168@vtext.com', '', 'Testing' );

How to send SMS from a website?

The example I present here shows how to send an SMS message from your website by clicking on a button. The idea we use is to have an HTML form, that allows the website visitor to enter a phone number and the message text. This HTML form can be submitted by clicking on the “SEND” button. Once submitted the form variables will be processed by a PHP script. This PHP script will post the SMS message to the SMS Gateway (Figure 1). As you can see on Figure 1. The SMS Gateway and your webserver (your webserver is hosting your HTML Form and your PHP script) can be on two different computers. If you wish you can install the Ozeki SMS Gateway software and the webserver with the HTML Form and the PHP script to the same computer.

send sms from a website
Figure 1 – Send SMS from a website

The first step in setting up this system, is to Install the Ozeki NG SMS Gateway to your computer and to verify, that you can send SMS messages from the gateway manually. After your SMS gateway is functioning you can create the HTML Form and the PHP script.

How to send SMS from a website?

The example I present here shows how to send an SMS message from your website by clicking on a button. The idea we use is to have an HTML form, that allows the website visitor to enter a phone number and the message text. This HTML form can be submitted by clicking on the “SEND” button. Once submitted the form variables will be processed by a PHP script. This PHP script will post the SMS message to the SMS Gateway (Figure 1). As you can see on Figure 1. The SMS Gateway and your webserver (your webserver is hosting your HTML Form and your PHP script) can be on two different computers. If you wish you can install the Ozeki SMS Gateway software and the webserver with the HTML Form and the PHP script to the same computer.

send sms from a website
Figure 1 – Send SMS from a website

The first step in setting up this system, is to Install the Ozeki NG SMS Gateway to your computer and to verify, that you can send SMS messages from the gateway manually. After your SMS gateway is functioning you can create the HTML Form and the PHP script.

A Test Drive

Let’s run a test with PHP to make sure that everything is set up correctly and that the mail function will, in fact, send a text message. Using the following code, we can run:

12345<?php var_dump( mail( '##########@vtext.com', '', 'This was sent with PHP.' ) ); // bool(true) ?>

When my phone receives the message, it looks like this:

PHP Email to SMS Tutorial PHP Send SMS Example

If you are getting an error, see the troubleshooting section.

As you can see in the PHP send SMS example above, the message shows that it’s from Gmail. This is because I route all my outgoing messages from my local server through that service. Unfortunately, as of this writing, I have been unsuccessful at altering the¬†From¬†header to reflect an alternate address. It seems that the email headers are stripped and replaced with headers prepared by the SMS gateway. If anyone knows of a workaround, please leave a comment and let the rest of us know!

Conclusion

Php Script for Sms Sending, php contact number script, php script sms mobile, best sms gateway php service provider.

0 Comments

No Comment.