Tutorials

SENDING SMS

				
					<?php 

// Assuming you have the necessary credentials to connect to your MySQL database 
$servername = "xxxxxx"; 
$username = "xxxxxxx"; 
$password = "******"; 
$dbname = "xxxxxxx"; 
// Create a connection to the database 
$conn = new mysqli($servername, $username, $password, $dbname); 
// Check the connection 
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error); 
} 
// Read the raw data from the incoming HTTP request's body 
$data = file_get_contents("php://input"); 
// Decode the JSON data into an associative array 
$decoded_data = json_decode($data, true); 
//put data to the msgdata.txt 
file_put_contents('msgdata.txt', $data, FILE_APPEND); 
// Check if JSON decoding was successful 
if ($decoded_data === null) { 
    echo "Error decoding JSON data."; 
    exit; 
} 
// Extract data from the new JSON structure 
$number = $decoded_data['number']; 
$message_code = $decoded_data['MsgFollowUpUniqueCode']; 
$status = $decoded_data['Status']; 
// Escape each value to prevent SQL injection 
$number = $conn->real_escape_string($number); 
$message_code = $conn->real_escape_string($message_code); 
$status = $conn->real_escape_string($status); 

// SQL query to insert the data into a table named 'egosmsdata' 
$sql = "INSERT INTO egosmsdb (number, message_code, status) VALUES ('$number', '$message_code', '$status')"; 
if ($conn->query($sql) !== TRUE) { 
    echo "Error in saving delivery report: " . $conn->error; 
    $conn->close(); 
    exit; 
} 
echo "delivery report saved successfully into the database."; 

// Close the database connection 
$conn->close(); 
?>