msg91 integration to php

We need to require messages and otp for different purpose in our projects, Such as sending information to cutomer via messages and if we want to verify user mobile number we need message and otp function to our project. Please follow the following steps :

Goto: https://msg91.com/in ( Create account first ).
https://docs.msg91.com/reference/send-sms ( choose php )

composer require guzzlehttp/guzzle ( type n means no if there is already have any folder of vendor )
https://api.msg91.com/apidoc/samplecode/php-sample-code-send-sms.php
msg.php

<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://control.msg91.com/api/v5/flow/', [
'body' => '{"template_id":"EntertemplateID","short_url":"1 (On) or 0 (Off)","recipients":[{"mobiles":"919XXXXXXXXX","VAR1":"VALUE1","VAR2":"VALUE2"}]}',
'headers' => [
'accept' => 'application/json',
'authkey' => 'Enter your MSG91 authkey',
'content-type' => 'application/json',
],
]);

echo $response->getBody();
For otp verification install this package

composer require sendotp/sendotp
otp.php

<?php

require __DIR__ . '/vendor/autoload.php';

use sendotp\sendotp;
// new sendotp('AUTK-KEY','Message Template : My otp is {{otp}}. Please do not share Me.');
$otp = new sendotp('397340A3YpuWar9HJ646d9219P1','Message Template : My otp is {{otp}}. Please do not share Me.');
print_r($otp->send('917746060757', 'MSGIND'));

?>

 

Leave a Reply