Script php ส่งข้อความเข้า Line โดยใช้ notify
<?php
// Replace 'YOUR_ACCESS_TOKEN' with your actual Line Notify access token.
$accessToken = 'YOUR_ACCESS_TOKEN';
// The message you want to send.
$message = "Hello, this is a Line Notify test message.";
// API URL for Line Notify.
$url = 'https://notify-api.line.me/api/notify';
// Set headers for the request.
$headers = array(
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/x-www-form-urlencoded',
);
// Prepare the POST data.
$data = array('message' => $message);
// Initialize cURL session.
$ch = curl_init();
// Set cURL options.
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute cURL session and get the response.
$response = curl_exec($ch);
// Close cURL session.
curl_close($ch);
// Process the response.
if ($response === false) {
echo 'Error sending Line Notify message: ' . curl_error($ch);
} else {
echo 'Message sent successfully!';
}