TWILIO MESSAGE SERVICE

Do some basic steps in TWILIO:

https://console.twilio.com/us1/account/manage-account/general-settings

https://console.twilio.com/us1/develop/sms/settings/geo-permissions

https://console.twilio.com/us1/develop/sms/try-it-out/send-an-sms

https://console.twilio.com/us1/monitor/logs/debugger/errors


Helper Function:


use Twilio\Rest\Client;
function sendSMS($req_dialCode,$req_number,$req_message){
    try{
        $account_sid =  env('TWILIO_SID');
        $account_token =  env('TWILIO_TOKEN');
        $account_from =  env('TWILIO_FROM');

        if(isset($req_dialCode) && isset($req_number)){
        $client = new Client($account_sid, $account_token);
       
        // $client->messages->create('+91'.$req_number,[

        $client->messages->create($req_dialCode.$req_number,[
            'body'=>$req_message,
            "messagingServiceSid" => "MG8705dcb3a7869e23e6bb8287243507d6"
            // 'from'=>$account_from,
        ]);             }
        return "Message sent.";
    }catch(\Exception $ex){
        return $ex->getMessage();
    }        
}


.env 
TWILIO_SID=value
TWILIO_TOKEN=value
TWILIO_FROM=value



Call from controller  or view functions

        $sms_res = sendSMS($user_details->dial_code, $user_details->cellphone,'Important: Your One-Time Password (OTP) for Account Security. Your OTP is : '.$otp.' . Keep it confidential.');



Comments

Popular posts from this blog

[[ ROYAL CAR ]] CHANGE PASSWORD - DYNAMIC BANNER - MULTIPLE IMAGE - LOGIN LOGOUT BACK BUTTON MIDDLEWARE STOP - MAIL DIRECTLY WITH FEEDBACK WITH SAVE IN SQL DB - ADMIN REPLY EXISTING MAILS - DYNAMICALLY CSS CHANGE

Sahari

Linux Terminal