Last active
October 26, 2021 08:42
-
-
Save JRyven/4babd66e018ee5e2a6d68b1c7c557fb5 to your computer and use it in GitHub Desktop.
Trigger Twilio Text Message as a result of form submission
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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