Send SMS from your website with this trick. (detailed guide)

Contact us to discuss your web project.

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.

Who is this tutorial for?

Our article is intended for three types of profiles:

  • Developers — who are keen to learn the procedure (for that, follow the steps).
  • Business owners — who don’t have enough time and want a usable solution (Download code).
  • Ordinary people — who are curious and would like to know more.

Requirements for developers

To follow this tutorial and easily apply it to your project, you must first meet a few criteria. Indeed, you must:

  • Possess basic skills in PHP.
  • Understand how HTML tags work.
  • Have some web programming skills.

For a business owner

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”]

The procedure for developers to integrate the sending of SMS

To be able to send SMS from your site, you must follow the steps below.

Step 1 – Create a Twilio account and get configuration settings

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.

How to create a Twilio account

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. Send SMS from your website with this trick. (guide)

Remarks

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.

Get API SID and Authentication Code

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. Send SMS from your website with this trick. (guide) Finally, copy these two pieces of information for your project.

Acquire your Twilio phone number

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. Send SMS from your website with this trick. (guide) 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

Step 2 – Twilio’s PHP Classes

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:

Download with Composer and generate the “Composer.phar” file.

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:

  • On the getcomposer.org website, click the “Getting Started” button. You will see the documentation for creating the composer.phar file.
  • Via the command line, run the code below.

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

Generate the composer.json file to download the Twilio SDK

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.

Include the Twilio SDK in your project

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.

Instructions for redeeming code
  • Replace the SID (line 9) as well as the code (line 10) with the identifiers you obtained in Step 1.
  • Then replace the phone number on line 16 with the phone number of the SMS recipient.
  • Finally, on line 19, replace the phone number with your Twilio phone number.

Step 3 – Create a form to send SMS 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.

Example code HTML-index.html

The HTML code corresponding to the above form is as follows.

Sample PHP-sendms.php action file code

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:

Conclusion

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.


What our clients say about us

“PrositeWeb is a very professional company. They have helped me with several projects, and I am very satisfied, especially with their respect for deadlines. They support us throughout all our processes. Thank you. ”

Odigues Joseph

President and founder – Oneevo Immobilier Inc.

“Très bonne expérience”

Garage Ayad

President – Garage Ayad

“Début 2024, nous avons travaillé avec Prositeweb, Gilblas et ce fût un véritable plaisir et succès. Ça se résume en suivi, communication et compétence. C'est ce qu'on recherche lorsqu'on confie un mandat web (API) personnalisé comme le nôtre. Chapeau, Prositeweb, Gilblas, je le recommande et je retravaillerai avec sans aucun doute.”

Martin Beaudet

Président – Authen Tic

Ce site utilise des cookies pour vous garantir la meilleure expérience sur notre site. En utilisant notre site, vous acceptez les cookies. Apprendre encore plus