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

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories