Scroll to top


Ever wondered how to send SMS message through Laravel App, here I am for your rescue. Today we will use Twilio a Cloud-Based Communication System some of the features include call routing, SMS, MMS, SIP, call recordings. Everything in Twilio can be done using its nice and powerful API. We will use Twilio to create our SMS sending the app.


Go to Twilio and click on Sign Up for Free. Fill out your details and click Get Started. Now Twilio will ask you mobile no which will be used to verify your account if SMS verification does not work then click on the call to verify your account. Once verified you will be redirected to Twilio tour after that go to dashboard you will see two fields ACCOUNT SID and AUTH TOKEN this are used to validate your app with Twilio Server. To reveal the AUTH TOKEN click on Lock Icon.  Click on Configure your Trial number on the dashboard to see your configured trial number. If you are using the trial account you cannot send SMS message to unverified numbers. To see all verified numbers click here, If there are no numbers in the list then add a new number. We will use our Twilio trial number to send SMS message to one of our verified numbers.  We will use official Twilio package for Laravel

Open composer.json and add below lines to require array

"twilio/sdk": "dev-master"

Now run

composer update


We will use bootstrap to style our message field and Send button . We will have only one view which will have a text field to enter message and a button to send the message .


        <script src="//"></script>
        <script src="//"></script>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="//">
        <!-- Optional theme -->
        <link rel="stylesheet" href="//">
        <!-- Latest compiled and minified JavaScript -->
        <script src="//"></script>
        <div class="container" style="margin-top:100px;">
            <div class="row">
                <div class="col-xs-6">
                    <input type="text" class="form-control" name="message"/>
                <div class="col-xs-6">
                    <button class="btn btn-success" type="submit">Send</button>


As you can see in index.blade.php we are submitting the form to / send. So we need two routes, first to display index page and second to send a message.

Route::get('/', 'SMSController@index');
Route::post('/send', 'SMSController@send');


Lets now create our SMSController. Our SMSController code is below

class SMSController extends BaseController {
    public function __construct() {
    public function index() {
        return View::make('index');
    public function send() {
        if (Input::has("message")) {
            $sid = "YOUR ACCOUNT SID";
            // Your Account SID from
            $token = "YOUR ACCOUNT AUTH TOKEN";
            // Your Auth Token from
            $client = new Services_Twilio($sid, $token);
            $message = $client -> account -> messages -> sendMessage('YOUR TRIAL/PAID TWILIO NUMBER', // From a valid Twilio number
            'YOUR VERIFIED NUMBER', // Text this number
            echo "Message Send Successfully Message SID :: " . $message -> sid;
        } else {
            echo "Error : No Message Entered <a href='/'>click here</a> to go back";

If everything is correct then you will see below message, for you, SID will be different.

To check logs click on Logs in the menu and click on any submenu like messages etc . Since we have sent a message output is shown below.

Feel free to comment if you have any doubt.




Author avatar

Imran is a web developer and consultant from India. He is the founder of KodeInfo, the PHP and Laravel Community . In the meantime he follows other projects, works as a freelance backend consultant for PHP applications and studies IT Engineering . He loves to learn new things, not only about PHP or development but everything.

Post a Comment

Your email address will not be published. Required fields are marked *