Skip to content

Instantly share code, notes, and snippets.

@JRyven
Last active October 26, 2021 08:42
Show Gist options
  • Save JRyven/4babd66e018ee5e2a6d68b1c7c557fb5 to your computer and use it in GitHub Desktop.
Save JRyven/4babd66e018ee5e2a6d68b1c7c557fb5 to your computer and use it in GitHub Desktop.
Trigger Twilio Text Message as a result of form submission
<?php
/**
* Send Information to Twilio, Require SKD https://www.twilio.com/docs/libraries/php
*
*
*/
require __DIR__ . '/twilio/Twilio/autoload.php';
use Twilio\Rest\Client;
/**
* Send Information to Twilio https://www.twilio.com/docs/libraries/php
*
*
*/
function estimate_published___twilio(){
if($_POST):
// Your Account SID and Auth Token from twilio.com/console
$sid = '############################';
$token = '############################';
$client = new Client($sid, $token);
$recipient = $_POST['phone']; // form submitter is recipient for this message
$client->messages->create(
$recipient,
array(
'from' => '+13333334444', // A Twilio phone number you purchased at twilio.com/console
'body' => 'We got your form submission! We will be in touch soon.'
)
);
$client->messages->create(
'+12223334444',
array(
'from' => '+13333334444', // A Twilio phone number you purchased at twilio.com/console
'body' => 'Your form got a new submission from: '.$recipient;
)
);
endif; // ENDIF IS $_POST
}
add_action( 'init', 'estimate_published___twillio', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment