__________     __ __     __  _______    ________
  / ____/ __ \   / // /    / / / /  _/ |  / / ____/
 / / __/ / / /  / // /_   / /_/ // / | | / / __/
/ /_/ / /_/ /  /__  __/  / __  // /  | |/ / /___
\____/\____/     /_/    /_/ /_/___/  |___/_____/

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

Integrate Twilio SMS Service in a Website using PHP

BY: @coderlovely | CREATED: March 13, 2018, 1:35 p.m. | VOTES: 3 | PAYOUT: $0.00 | [ VOTE ]

What Will I Learn?
Now we are going to learn how to setup and use Twilio for sending text messages to single/multiple recipients.

Requirements
PHP Server
Basic knowledge about PHP

Difficulty
Basic

Many people want to integrate Short Messaging Service into web applications to send notifications, promotions, reminders to their clients or members from their websites. This can be done using Twilio. Twilio is a cloud communications company that allows developers to programmatically send and receive text messages and make and receive phone calls using its web service APIs. Now we are going to learn how to setup and use Twilio for sending text messages to single/multiple recipients.

[IMAGE: https://i.hizliresim.com/Z9RrRZ.png]

In this project I have used The Twilio PHP Helper Library by Twilio. Let’s start with setting up Twilio account first

Twilio Account Setup:
Step 1: Go for http://twilio.com and Signup for a new Twilio account or Sign in if you already have one.

Step 2: To get started with Twilio you can sign up for a trial account at https://www.twilio.com/try-twilio.

Step 3: Verify your phone number as an outbound caller ID with Twilio. For information on how to verify your phone number, see https://www.twilio.com/user/account/phone-numbers/verified#. For purposes of this example, use the verified phone number as text message recipient in this application.

Note: If you are using a trial account, then its compulsory to use only your own verified phone number for receiving text messages. As an alternative to using an existing number, you can purchase a Twilio phone number.

Step 4: Get account SID and Auth Token from https://www.twilio.com/user/account which will be used in this application.

[IMAGE: https://i.hizliresim.com/lORo8X.png]

Step 5: Get your Twilio account phone number from https://www.twilio.com/user/account/phone-numbers/incoming which will be used as sender in text messages.

[IMAGE: https://i.hizliresim.com/G9XqJ2.png]

PHP Code:

We will be working with config.php, example.php, integrate.php and functions.php. Proper understanding of these files is necessary.

config.php:


functions.php:

This file has two functions. send_message function is used to send message to a single recipient. It has two parameters ($receiver and $message). $receiver contains number to which text message will be sent. $message is body of the message.

send_multiple_message function is used to send text messages to multiple recipients. It also has two parameters, the only difference is that $receiver has multiple recipients separated with a comma( , ).

account->messages->sendMessage(
      $my_number, // From a valid Twilio number
      $receiver, // Text this number
      $message
    );

    return $result->sid;  

}

// This function will be used to send message to multiple recipient.
function send_multiple_message($receiver, $message)
{
    require "config.php";
    require './twilio-php/Services/Twilio.php';
    $numbers  =  explode("," , $receiver);
    $receipt = array();
    $count = 0;
    foreach($numbers AS $num)
    {

        $client = new Services_Twilio($sid, $token);
        $result = $client->account->messages->sendMessage(
          $my_number, // From a valid Twilio number
          trim($num), // Text this number
          $message
        );

        $receipt[$count]["num"] = $num;
        $receipt[$count]["sid"] = $result->sid;

    }

    return $receipt;

}

?>

example.php:

This file can send message to a single recipient. HTML Form with $_POST method is used to send data.

Message Sent....SID Returned By Twillio is: $result";
  }

} 

?>


To send Text Message to multiple recipients Click Here




function submit()
{
    document.getElementById("sendsms").submit();
}




Send To:   
Message:  
Message length:160 characters max..



integrate.php:

If you want to send message without HTML Form use below code in any desired PHP file.

Message Sent....SID Returned By Twilio is: $result";
  }

}

Posted on Utopian.io - Rewarding Open Source Contributors

TAGS: [ #utopian-io ] [ #utopian ] [ #utopianio ] [ #php ]

Replies

@arie.steem | March 13, 2018, 5 p.m. | Votes: 1 | [ VOTE ]

Your contribution cannot be approved because it does not follow the Utopian Rules.

  • you already get banned because doing plagiarism before : https://utopian.io/utopian-io/@coderlovely/methods-of-creating-a-web-part-page
  • and all of your contribution will be rejected.

You can contact us on Discord.
[utopian-moderator]

@steemitboard | March 2, 2019, 11:42 p.m. | Votes: 0 | [ VOTE ]

Congratulations @coderlovely! You received a personal award!

https://steemitimages.com/70x70/http://steemitboard.com/@coderlovely/birthday1.pngHappy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Do not miss the last post from @steemitboard:

Carnival Challenge - Collect badge and win 5 STEEM

Vote for @Steemitboard as a witness and get one more award and increased upvotes!
@steemitboard | March 5, 2020, 4:31 a.m. | Votes: 0 | [ VOTE ]

Congratulations @coderlovely! You received a personal award!

https://steemitimages.com/70x70/http://steemitboard.com/@coderlovely/birthday2.pngHappy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

Use your witness votes and get the Community Badge

Vote for @Steemitboard as a witness to get one more award and increased upvotes!
[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>