Send SMS messages with a function using Twilio and PHP

January 18, 2024


// Download source files here:
// https://github.com/twilio/twilio-php#:~:text=with%20GitHub%20Desktop-,Download,-ZIP
// Unzip and upload the source files to a folder below the public web folder

// include the source files at the top of your page
require('/root/includes/twilio-php-main/src/Twilio/autoload.php');

use Twilio\Rest\Client;

$twilio_account_sid = '*********';
$twilio_auth_token = '*********';
$twilio_from_number = '5555555555';
$twilio_to_number = '6666666666';
$twilio_message = 'Are you up??';

function sms($twilio_to_number,$twilio_message){
global $twilio_account_sid,$twilio_auth_token,$twilio_from_number;

$client = new Client($twilio_account_sid, $twilio_auth_token);
$client -> messages -> create(
	'+1' . $twilio_to_number,
    array(
        'from' => $twilio_from_number,
        'body' => $twilio_message
    )
);
};


// Usage
$twilio_to_number = '5556668888';
$twilio_message = 'This is a test...';

sms($twilio_to_number,$twilio_message);



Comments

There are no comments.


Comment on this Article

Your email address will never be published. Comments are usually approved within an hour or two. (to prevent spam)