Categories: WordPress

How To Send Twilio SMS From WordPress?

With SMS notifications, you can stay in touch with your customers or clients.

In this article, we learn how to send Twilio SMS from WordPress.

Twilio account is used to send SMS notifications. Create an account if you don’t have one already. Please review below URL,

https://www.twilio.com/try-twilio

Here we are using the API of Twilio to send SMS.

To get “Account SID” and “Auth Token” of the Twilio account, Please follow below steps:

Step-1: Login Twilio account and go to the dashboard

Step-2:  Copy “Account SID”, “Auth Token” and “Phone Number”.

You can use this code any hook like “wp_ajax” and “init” action. Add below code in functions.php,

$username = "Account SID";
$password = "Auth Token";
$auth = base64_encode( $username . ':' . $password );
$args = [
  'headers' => [
    'Authorization' => "Basic $auth",
    'Content-Type'  => 'application/x-www-form-urlencoded;charset=UTF-8',
  ],
  'body'    => [
    "Body" => 'Testing twilio message body',
    "To"   => "Receiver Mobile Number",
    "From" => "Twillio Register Mobile Number",
  ],
];       
  
$response      = wp_remote_post( 'https://api.twilio.com/2010-04-01/Accounts//Messages.json', $args );
$response_body = wp_remote_retrieve_body( $response );

Here,
Username : Account SID,
Password : Auth Token
To : Receiver Mobile Number
From : Twillio Register Mobile Number

Jigna Mavani

I am a Senior WordPress developer at vision Infotech. I'm specialized in WordPress, WooCommerce, PHP, HTML, and jQuery.

Share
Published by
Jigna Mavani

Recent Posts

Testing hk

Testing

1 year ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

1 year ago

Operation

Testing

1 year ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

1 year ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

1 year ago

TETS NEW

test

2 years ago