This recipe is the brain of the system; it handles users sending in responses and also handles what to do if a user wants to be unsubscribed. This script will listen on a phone number and do exactly that.
The listener.php
file replaces tracker.php
, and it will handle pausing, resuming, and the responses.
Let's build on our previous subscriber tracker and add some extra functionality. We'll call this recipe listener.php
.
Upload the
listener.php
file (with the following content) on your web server.<?php include("config.php"); include("pdo.class.php"); $pdo = Db::singleton(); if( isset($_POST['Body']) ){ $phone = $_POST['From']; $phone = str_replace('+','',$phone); $action = strtolower($_POST['Body']); switch($action){ case "pause": $sql = "UPDATE subscribers SET status=0 WHERE phone_number='{$phone}'"; $pdo->exec( $sql...