PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 18, 2022

[FIXED] How to send bulk sms in twilio api without for loop

 November 18, 2022     php, twilio, twilio-api, twilio-php     No comments   

Issue

I'm trying to send bulk sms through twilio Api. Is there any method to pass the array of all phone numbers in a single API request.


Solution

Twilio developer evangelist here.

Yes there is now! It's known as the passthrough API (as it allows you to pass through many different messaging systems and send bulk messages. It's part of the Notify API and you can use it to send bulk SMS messages. You need to set up a messaging service and a notify service in your console, then you can use the following code:

<?php
// NOTE: This example uses the next generation Twilio helper library - for more
// information on how to download and install this version, visit
// https://www.twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php';

use Twilio\Rest\Client;

// Your Account SID and Auth Token from https://www.twilio.com/console
$accountSid = "your_account_sid";
$authToken = "your_auth_token";

// your notify service sid
$serviceSid = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Initialize the client
$client = new Client($accountSid, $authToken);

// Create a notification
$notification = $client
    ->notify->services($serviceSid)
    ->notifications->create([
        "toBinding" => [
            '{"binding_type":"sms", "address":"+15555555555"}',
            '{"binding_type":"sms", "address":"+12345678912"}'
        ],
        "body" => "Hello Bob"
    ]);

Checkout the documentation on sending multiple messages with the Notify passthrough API for all the details.



Answered By - philnash
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing