function message_to_telegram($text, $image)
{
$ch = curl_init();
curl_setopt_array(
$ch,
array(
CURLOPT_URL => 'https://api.telegram.org/bot' . TELEGRAM_TOKEN . '/sendMessage',
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 10,
CURLOPT_POSTFIELDS => array(
'chat_id' => TELEGRAM_CHATID,
'text' => $text,
disable_web_page_preview => true,
parse_mode => "Markdown",
"photo" => $image
),
)
);
curl_exec($ch);
$bot_url = 'https://api.telegram.org/bot' . TELEGRAM_TOKEN . '/';
$url = $bot_url . "sendPhoto?chat_id=" . TELEGRAM_CHATID;
$chPhoto = curl_init();
curl_setopt($chPhoto, CURLOPT_HTTPHEADER, array(
"Content-Type:multipart/form-data"
));
curl_setopt($chPhoto, CURLOPT_URL, $url);
curl_setopt($chPhoto, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($chPhoto, CURLOPT_POSTFIELDS, array(
"photo" => $image,
));
curl_setopt($chPhoto, CURLOPT_INFILESIZE, filesize($image));
$output = curl_exec($chPhoto);
}
$document = new CURLFile($txtFileName, 'image/jpeg', '1.jpg');
$params = [
'chat_id' => $chatId,
'document' => $document,
'caption' => $caption,
];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($curl);
curl_close($curl);