Developer Tools
BasicText SMSCampaignOTPVirtual NumberResellerSample CodePhonebookError Code
HOME LOGIN SIGN UP
  • OTP Message
  • Verify OTP
  • Resend OTP
  • Sample Code
    • » PHP
    • » Python

PHP Sample Code Send SMS

Code:

<?php

//For sending OTP
$url="http://world.msg91.com/api/otp.php"; $postData = array( 'authkey' => "YourAuthKey", 'mobile' => "99xxxxxxxx", 'message' => urlencode("Test message"), 'sender' => "YourSender", 'otp' => 'YourOTP' ); $paramArr['url'] = $url; $paramArr['postData'] = $postData; sendRequest($paramArr);

// For Verify otp $url="http://world.msg91.com/api/verifyRequestOTP.php"; $postData = array( 'authkey' => "YourAuthKey", 'mobile' => "99xxxxxxxx", 'otp' => 'YourOTP' ); $paramArr['url'] = $url; $paramArr['postData'] = $postData; sendRequest($paramArr);

// For Retry otp $url="http://world.msg91.com/api/retryotp.php"; $postData = array( 'authkey' => "YourAuthKey", 'mobile' => "99xxxxxxxx", 'retrytype' => 'text/voice' ); $paramArr['url'] = $url; $paramArr['postData'] = $postData; sendRequest($paramArr); function sendRequest($param){ $url = $param['url']; $postData = $param['postData']; $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postData //,CURLOPT_FOLLOWLOCATION => true )); //Ignore SSL certificate verification curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //get response $output = curl_exec($ch); //Print error if any if(curl_errno($ch)) { return curl_error($ch); } curl_close($ch); return $output; } ?>

© 2008-2025 | All Rights Reserved.