Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Twilio sms sending in express

const smsSid = process.env.SMS_SID
const smsAuthToken = process.env.SMS_AUTH_TOKEN
const twilio = require('twilio')(smsSid, smsAuthToken, {
    lazyLoading: true,
});

async sendBySms(phone, otp) {
        return await twilio.messages.create({
            to: phone,
            from: process.env.SMS_FROM_NUMBER,
            body: `Your codershouse OTP is ${otp}`,
        });
    }
Comment

twilio sms does not show sender number

Why do some SMS recipients see a Sender ID that is not my Twilio number?
Sender ID change may occur when you send messages from a Twilio number that is not local to your recipients, for example using a US Twilio number to send SMS to Polish mobile users. This is often done to comply with local regulations, or to ensure the highest possible delivery rate for your messages.

Sender ID change will not occur when you send messages using a Twilio number from the same country as the recipient, for example using a Polish Twilio number to send SMS to a Polish mobile user.

Sender ID change does not negatively affect delivery quality, however it means that replies from recipients will not be routed back to your Twilio number.

If you need to receive SMS replies from your users, please use a Twilio phone number or short code from the same country as your recipients. This will ensure Sender ID is preserved. For more info, see Receiving Two-Way SMS and MMS Messages with Twilio
Comment

send sms with twilio

function send_sms($number,$body)
{
    $ID = '1234567890abcdef1234567890abcdef12';
    $token = '1234567890abcdef1234567890abcdef';
    $service = 'AB1234567890abcdef1234567890abcdef';
    $url = 'https://api.twilio.com/2010-04-01/Accounts/' . $ID . '/Messages.json';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);

    curl_setopt($ch, CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD,$ID . ':' . $token);

    curl_setopt($ch, CURLOPT_POST,true);
    curl_setopt($ch, CURLOPT_POSTFIELDS,
        'To=' . rawurlencode('+' . $number) .
        '&MessagingServiceSid=' . $service .         // this is optionnel
        //'&From=' . rawurlencode('+18885550000') .  // this is required
        '&Body=' . rawurlencode($body));

    $resp = curl_exec($ch);
    curl_close($ch);
    return json_decode($resp,true);
}

/*
$ID and $token can be found under SMS / Dashboard / 'Show API Credentials' https://www.twilio.com/console/sms/dashboard

(Optional) $service can be found under SMS / Messaging Services / 'SID' https://www.twilio.com/console/sms/services

Comment out 'MessagingServiceSid=' and uncomment 'From=' to use direct sending from a single phone number

Finally, key information can be found buried in the kb here https://www.twilio.com/docs/sms/send-messages#send-a-message-with-an-image-url

*/
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to fetch api in class component react 
Javascript :: js destructuring 
Javascript :: how to get 6 months after date object 
Javascript :: 9 + 10 
Javascript :: chrome extension contextmenus 
Javascript :: how to upload picture on canvas in react 
Javascript :: connect node with react 
Javascript :: create array of numbers javascript 
Javascript :: updatedAt mongoose stop 
Javascript :: on close tab react native web 
Javascript :: check cookies client side 
Javascript :: how to connect ms access database in html using javascript 
Javascript :: ReactComponent as Icon 
Javascript :: apartments api 
Javascript :: react native update app from play store ios app store 
Javascript :: update head tag metadata vue 
Javascript :: javascript find missing number 
Javascript :: load js 
Javascript :: react insert variable into string 
Javascript :: dayjs dayofyear 
Javascript :: javascript array find case insensitive 
Javascript :: wordpress get plugin url in javascript 
Javascript :: add table header dynamically in jquery 
Javascript :: js bind prototype arrow function 
Javascript :: promise.all jquery ajax 
Javascript :: angular2-tree-diagram 
Javascript :: JavaScript Local Scope Variable 
Javascript :: remove string from outside array javascript 
Javascript :: date range picker react 
Javascript :: how to create new route in express 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =