Sample php code for sending OTP

Most of the user oriented website are slowly changing from email and password based login to OTP based for a developer it is necessary to know how to create on OTP based login, here am going to share you Sample PHP code for sending OTP.

First you have to Register with any of the SMS Service providers ,here am using mysmsmantra.Here we are achieving with the help of CURL in PHP,this is the URL API from mysmsmantra for sedning OTP*******&message=your OTP
where YOUR_USERNAME and YOUR_PASSWORD are respectively user name and password from mysmsmantra.

$otp=rand(100000, 999999);
$msg="Dear Customer, One Time Password for activating your account is :".$otp;
//YOUR_USERNAME and YOUR_PASSWORD are respectively from mysmsmantra
$ch = curl_init($messageUrl); 
$fp = fopen("message.txt", "w+"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FILE, $fp); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_exec($ch); curl_close($ch); 


Leave a Reply

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