Skip to content

Instantly share code, notes, and snippets.

@JaniKibichi
Last active January 27, 2022 10:46
Show Gist options
  • Save JaniKibichi/92a9bef0169c53dcab1eeedb3168ad1a to your computer and use it in GitHub Desktop.
Save JaniKibichi/92a9bef0169c53dcab1eeedb3168ad1a to your computer and use it in GitHub Desktop.
Shortcode
<?php
//receive the POST from AT on your POST ROUTE
$from = $_POST['from'];
$to = $_POST['to'];
$text = $_POST['text'];
$date = $_POST['date'];
$id = $_POST['id'];
$linkId = $_POST['linkId'];
//Respond based on backend events
if(!empty($_POST['from'])){
//1. Store to DB
//MYSQL Queries
//2. Send Auto Message
require_once('AfricasTalkingGateway.php');
//3.can store as ENV variables
$username = "MyAfricasTalkingUsername";
$apikey = "MyAfricasTalkingAPIKey";
$recipients = $from;
$message = "I'm a lumberjack and its ok, I sleep all night and I work all day";
//4. Specify your AfricasTalking shortCode or sender id
$from = "shortCode or senderId";//"20414"
$gateway = new AfricasTalkingGateway($username, $apikey);
try {
$results = $gateway->sendMessage($recipients, $message, $from);
//5.Store to DB
}catch ( AfricasTalkingGatewayException $e )
{
echo "Encountered an error while sending: ".$e->getMessage();
}
}
//6. Other logic to send from a POST form.
//7. Subscription
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment