This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

CloudwaysCDN — a powerful solution that offers superior performance and satisfied global audience for your business. Read More

How to Send SMS From a Cloud Server Using Twilio

Updated on  20th September

4 Min Read
Reading Time: 4 minutes

When you are running business applications like ecommerce stores, web applications, customer-specific applications, and banking apps, you need to reach out to your customers by any medium of communication like email, calls, and SMS messages.

We know that billions of people use cell phones, and it makes it much easier to reach out to them. Here’s a research developed by Statista on the evaluation of cell phone usage since 2013 and it is forecasted that there will be around 5.07 billion cellphone users by 2019.

Mobile Phone Users

We have SMS services like Twilio to reach out our customers and take advantage of the figures. Twilio is a cloud communication platform which provides APIs of messaging, voice calls, and video calls.

send sms with twilio

In this article, we are using Twilio Messaging API on Cloudways server to send SMS messages to customers. I am assuming that you’ve already setup the new server on Cloudways and launched a PHP stack application.

Now, we have to follow 5 easy steps to setup Twilio API on Cloudways.

Let’s get started.

Step 1: Register Account on Twilio

You need to register an account on Twilio first. After signing up you will get your API credentials that includes Account SID and Auth Token. After registration, go to Account settings where you can see the secret Twilio API information.

Twilio provides two sets of API credentials if you have a trial account.

Login and head over Account settings where you’ll see these.

Register Account on Twilio

You can use TEST credentials for testing purpose in your apps but when you are upgrade to a premium account you will need the LIVE credentials. Since we have trial account, we will use the test credentials.

Step 2: Enable Geographic Permissions

Twilio provides its services worldwide but you can enable and disable it by configuring geographic permissions. Go to Account settings, scroll down, and you will see the settings for SMS and Voice geographic permissions.

Enable Geographic Permissions

We are setting up SMS API so click on SMS geographic permissions then filter your country to enable checkbox in it.

SMS API settings

Step 3: Verify Numbers to Send Message

Twilio will ask you to verify your phone number on trial account. To verify the number move to Verification Page and enter your digits.

Verify Numbers to Send Message

Click on the “Text Me” button and you will get a verification code. Enter the code in the next verification window and click on Submit button. You have successfully verified your number.

Step 4: Download Twilio Libraries

To send messages from Twilio on Cloudways, you need to create a cloud server.

php server stack

After creating a server, launch PHP stack application and download Twilio API files in your projects. Let’s download the library from the SSH terminal inside Cloudways. You can find it in the Server Tab. Move it to your public_html folder by using this command:

Now, run the following command to install Twilio library:

Step 5: Create index.php File in Cloudways Server

It’s time to move to Cloudways server and create an index.php file to add some code. Move to server area and find your Master Credentials and connect to you server with FileZilla.

Create index.php File in Cloudways Server

After connecting it to FileZilla, move to application/{your app folder}/public.html and edit index.php file by adding the following code:

You might be interested at: How To Get Server And App SMS Alerts Using Twilio And CloudwaysBot

We have finally setup Twilio API on Cloudways server to send messages in a simple way. You can also customize it and use forms with validation strategies. Extend the functionality of this service as per your requirements.

Share your opinion in the comment section. COMMENT NOW

Shahroze Nawaz

Shahroze is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. He’s always in search of new frameworks and methods to implement them. Besides his coding life, he loves movies and playing soccer with friends. You can email him at shahroze.nawaz@cloudways.com

Create PHP websites without the worry of server management.

Deploy your PHP app on optimized PHP hosting servers.

Get Our Newsletter
Be the first to get the latest updates and tutorials.

THERE’S MORE TO READ.