How to Send Bulk SMS with Twilio and Laravel PHP
Time to read: 2 minutes
There are times when you have a large number of users and you need to update or notify them simultaneously via SMS. Maybe you run a membership site or personal blog. Whatever the case this tutorial will provide an efficient and easy way to achieve sending bulk SMS via your web app.
Technical Requirements
For this tutorial we’ll assume you already know or have the following:
- A Terminal (Command Line)
- Composer installed
- Are familiar with PHP
- Are familiar with Laravel (5+)
- You have an existing Laravel (5+) project
- You have a Twilio account and your credentials ready
Just in case you don’t have a Laravel project setup, this guide will help you to create a new Laravel project locally.
Install and Configure the Twilio Laravel SDK
The first thing we need to do is install the Twilio Laravel SDK which will provide the needed functions to get our bulk SMS app started. We’ll use the command line to achieve that. So in the command line type:
Now that we have the SDK installed, we need to configure it to recognize our Twilio account. Open up your .env
file and paste in the following code. Be sure to replace the variables with your Twilio credentials. TWILIO_FROM
is your Twilio Number.
Setup the Controller and View
We need a controller specially for our BulkSMS app, so paste in the command below to create a controller using Laravel’s artisan console.
Open the controller and include the Twilio class at the top:
Next we will create a view file called bulksms.blade.php
to make an HTML form to create the necessary fields for our bulk SMS app.
Open up the newly created file located at resources/views/bulksms.blade.php
and paste in the code below:
Open up web.php
located in the routes
folder and paste in the following code at the bottom:
Now we will write a function to validate our HTML form and send out the text messages. Open up the BulkSmsController.php
file located at app/Http/Controllers
folder and type in the following code before the last curly brace.
Testing
To test your app open up your console in the project directory and type in following command:
Now using your preferred browser visit http://localhost:8000/bulksms, fill out the form and submit.
Conclusion
Now that you have set up a Bulk SMS sending app you can see how easy it is extend the SMS functionality. This gives you an advantage of having your phone numbers stored in your own database.
Twitter: @_masterpreshy
Github: https://github.com/Preshy
Website: http://masterpreshy.com
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.