+ 2

How to send form data via sms in php

30th Nov 2017, 5:44 PM
Thasniya Kader
Thasniya Kader - avatar
3 Answers
+ 3
PHP by itself has no SMS module or functions and doesn't allow you to send SMS.You can use an API or service integration with asterisk for example.There is an api called Twilio. You have make a HTTP POST to Twilio with the body of the message and the phone number you want to send it to. There are some bureaucracies to use this twilio, I think you have to register your number, for free users has limits of messages. There are particularities for each country.
30th Nov 2017, 5:54 PM
Malkon F
Malkon F - avatar
+ 3
<?php /* Send an SMS using Twilio. You can run this file 3 different ways: * * 1. Save it as sendnotifications.php and at the command line, run * php sendnotifications.php * * 2. Upload it to a web host and load mywebhost.com/sendnotifications.php * in a web browser. * * 3. Download a local server like WAMP, MAMP or XAMPP. Point the web root * directory to the folder containing this file, and load * localhost:8888/sendnotifications.php in a web browser. */ // Step 1: Get the Twilio-PHP library from twilio.com/docs/libraries/php, // following the instructions to install it with Composer. require_once "vendor/autoload.php"; use Twilio\Rest\Client; // Step 2: set our AccountSid and AuthToken from https://twilio.com/console $AccountSid="ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; $AuthToken = "your_auth_token"; // Step 3: instantiate a new Twilio Rest Client $client = new Client($AccountSid, $AuthToken); // Step 4: make an array of people we know, to send them a message. // Feel free to change/add your own phone number and name here. $people = array( "+15558675309" => "Curious George", "+15558675308" => "Boots", "+15558675307" => "Virgil" ); // Step 5: Loop over all our friends. $number is a phone number above, and // $name is the name next to it foreach ($people as $number => $name) { $sms = $client->account->messages->create( // the number we are sending to - Any phone number $number, array( // Step 6: Change the 'From' number below to be a valid Twilio number // that you've purchased 'from' => "+15017250604", // the sms body 'body' => "Hey $name, Monkey Party at 6PM. Bring Bananas!" ) ); // Display a confirmation message on the screen echo "Sent message to $name"; }
30th Nov 2017, 6:14 PM
Malkon F
Malkon F - avatar
+ 1
Thank youâ˜ș
30th Nov 2017, 6:15 PM
Thasniya Kader
Thasniya Kader - avatar