Search code examples
phpsms-gateway

Sending SMS via PHP


I am woking on my final year project and I would like to send sms to a client via php.

Is there any way in which I can use my cell phone as a GSM modem and send sms via php?

I tried "Ozeki NG - SMS Gateway" but not sure how to send sms via php.

if anyone has used/tried "Ozeki NG - SMS Gateway" then please let me know how to use it properly?

Any suggestions please do let me know.

I have a nokia 701. Can it be used as a gsm modem?.

Thank you


Solution

  • I assume that you already have sms service from msg91 using above setup or you can use any sms service providers like Twilio, Nexmo etc. Now i am creating a common function which you can call anywhere in your PHP code to send any type of text sms.

    //send otp message
    public static function sendMessage($mobile, $message)
    {
        $message = urlencode($message);
        $url = sprintf("http://api.msg91.com/api/v2/sendsms?authkey=%s&mobiles=%s&message=%s&sender=%s&route=%s",
            env('MSG91_AUTH_KEY'), $mobile, $message, env('MSG91_SENDER_ID'), env('MSG91_ROUTE'));
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
    

    For more details and step by step execution follow below link :

    https://www.lelocode.com/posts/sending-sms-like-otp,-welcome-message,mobile-verification-using-php---lelocode