<?php
require_once '../Twilio/autoload.php';
include('db.php');

use Twilio\Rest\Client;

// Twilio credentials
$accountSid = 'AC8bac449b32a1fe6070f736d142cbac1f';
$authToken  = '8e489af7dfa15b610298953e184de89d';

// Create a Twilio client
$client = new Client($accountSid, $authToken);

    $Sender = '+13322308524';
    $Receiver = $_POST['phone'];
    $Message = $_POST['message'];
    $current_date_time = date("d-m-Y h:i:sa");
// Send SMS
$message = $client->messages->create(
    $Receiver,
    [
        'from' => $Sender,
        'body' => $Message
    ]
);

$Message = preg_replace('/[^A-Za-z0-9 ]/', '', $Message);
 $Query = "INSERT INTO SMS (Sender, Receiver, Body, Status, Type, Message_Id,  Seen, created_at, updated_at)
               VALUES ('$Sender', '$Receiver', '$Message', 'Success', 'Send', '$message->sid', '1', '$current_date_time', '')";
 
    $Insert = mysqli_query($conn, $Query);
