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
Post a Comment