<?php

$clientId = 'YOUR_CLIENT_ID';
$clientSecret = 'YOUR_CLIENT_SECRET';
$phoneNumber = '0165171440';
$message = 'Hello from PHP! This is an automated message.';

$data = json_encode(array(
    'phone' => $phoneNumber,
    'message' => $message
));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.whatsapp.com/v1/messages');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Authorization: Basic ' . base64_encode($clientId . ':' . $clientSecret)
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

if ($httpCode == 201) {
    echo 'Message sent successfully.';
} else {
    echo 'Failed to send message. HTTP status code: ' . $httpCode;
}
