Sending otp sms in php is very simple. We need to use php rand() function to generate otp in php. rand() is a function which takes two parameters, and generates a random number. The two parameters basically specify a range, that is the upper limit and lower limit. Say, you want to generate a OTP of 6 digits so you can provide two range 200000 and 999999. The generated number will always be between 200000 and 999999. After the OTP is generated we send it to the mobile number via a sms gateway.