Sending SMS from your website with Twilio is relatively easy, it all depends on the programming language you use. Marketing by email and phone calls has lost its popularity. Indeed, a study has shown that the rate of opening emails has dropped significantly recently. If you own a website and are planning to try SMS marketing as an additional way to target customers, this article is for you. In this guide, we’ll show you how to send SMS from your website with Twilio. You will therefore be able to add the Twilio SDK to your project to integrate a form for sending SMS. You will also see how to get a Twilio number and an API for your project.
Our article is intended for three types of profiles:
To follow this tutorial and easily apply it to your project, you must first meet a few criteria. Indeed, you must:
If you like, you can read the article to understand how it works. However, we have provided two options to help you:
Please contact us if you have any questions. [the_call_to_action title=”Get a copy of the code for sending an SMS from your site. The code is ready to use and documented” action_text=”Download” action_type=”modal” action_link=”exampleModal” data_title=” Get the extension download link directly in your email ” data_action =” download ” data_link=”prositeweb_paiement”]
To be able to send SMS from your site, you must follow the steps below.
To start, you must create a Twilio account and acquire certain parameters such as the API SID, the API authentication code, and the telephone number. For example, in your dashboard, you can create API credentials for your project. When you register, you acquire a personalized phone number that you can then use to automate the sending of SMS.
To create a Twilio account, go to twilio.com and click on “register”. Next, a registration form that gives you the opportunity to try for free will appear. The next step will be to enter your email address, then a password. You will then receive a confirmation request by email. Then, you will only have to approve your account to access it. Initially, you will have free credit that you can use to send SMS from your site or to benefit from other Twilio services.
The procedure for creating an account on Twilio sometimes varies according to their general conditions. I advise you to follow and read the steps of the registration procedure.
Log in to your account, and your dashboard (the console) will appear. You will then find your SID account as well as your authentication code by scrolling down the page. Finally, copy these two pieces of information for your project.
All new users can acquire a free trial phone number for Twilio. To do this, just click on the “get a phone number” button on the home dashboard. Also, if you want to pay for a phone number, follow the “Phone numbers>Manage>Buy a number” menu. You can then view your phone numbers by going to the left menu and following “Phone numbers>Manage>Active numbers”. Note that the site is displayed in English. However, you can opt to read a guide in French by clicking on “Démarrez ici”
Thanks to the PHP classes or the SDK, you can easily interact with the APIs. For downloading, you have the choice between doing it manually or using the Composer. In this case, we usually recommend the Compositor. Indeed, the latter is downloaded with all the updates. Furthermore, doing a manual update brings the risk of running into an outdated or missing dependency update. However, we will see how to use both approaches:
More information about using the Composer can be found at getcomposer.org. You will therefore find instructions as well as detailed documentation on how to use the composer within the framework of a project. Note that you must have command line access to use and download the composer. Here are the general steps to follow:
Note that you may need to change the version of the sha256 depending on the current version. See the related article on getcomposer.org for more details. Running the code above will generate the composer.phar file. Thus, all you have to do is generate the composer.json file
If you want to have further information on how to create the composer.json file, refer to the official documentation. For this tutorial, you just need to create the composer.json file and paste the following code. Then from the command line run the statement
composer require twilio/sdk
If you follow the instructions carefully, you will see some PHP files for your projects, as well as a new folder named vendor in your main directory.
If so far all the steps have gone smoothly, you can then integrate the SDK, and start sending SMS from your website. The code below will help you send an SMS to any recipient from your website.
Now having the code to send an SMS, you can opt for the creation of a form that will avoid you to make manual sending. For example, with the code above, you can modify the message, and the recipient’s phone number to send the SMS. However, if you want to automate the process, you need to create a form from your dashboard. Below is an example of a form you can use.
The HTML code corresponding to the above form is as follows.
In addition to the HTML code, you will use an action file (PHP) which will receive a variable and send it to the recipient of the SMS. Your PHP action could be similar to the code below:
The process of sending an SMS from your website is simple with Twilio. You can use it with various programming languages. Moreover, if you have skills in the development of plugins or extensions, Twilio offers the possibility of converting it into a CMS extension. If you require supplemental information, please contact us, it will be a pleasure to help you.