<?php
require_once 'Twilio/autoload.php';
 // Twilio SDK

use Twilio\Rest\Client;

// Twilio WhatsApp credentials
$account_sid = 'AC4f7ac9843b7efcb2f255653d5715436b';
$auth_token  = '82b9a6552d888dc6bd81629589790b23';
$twilio_whatsapp_number = 'whatsapp:+14155238886'; // Twilio sandbox number or approved WhatsApp number

$client = new Client($account_sid, $auth_token);

// Get POST data
$name  = isset($_POST['name']) ? $_POST['name'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';

if(!$name || !$phone){
    http_response_code(400);
    echo 'Invalid input';
    exit;
}

// Fixed recipient WhatsApp number (your number)
$recipient_number = 'whatsapp:+919971084321';

// Message content
$message = "New Call Back Request:\nName: $name\nPhone: $phone";

try {
    $client->messages->create(
        $recipient_number,
        [
            'from' => $twilio_whatsapp_number,
            'body' => $message
        ]
    );
    echo 'Message sent successfully';
} catch(Exception $e) {
    http_response_code(500);
    echo 'Error: ' . $e->getMessage();
}
?>
