Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
<?php
//
$TOKEN = "TOKEN";
$CHAT_ID = "CHAT_ID";
/
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$product = $_POST['product'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$attachments = $_FILES['attachments'];
$invoice = $_FILES['invoice'];
$message = "Form\n";
$message .= "Name: ".$product." \n";
$message .= "Sender: ".$name." \n";
$message .= "phone: ".$phone." \n";
$message .= "Email: ".$email;
file_get_contents("https://api.telegram.org/bot$TOKEN/sendMessage?cha...);
function sendFile($TOKEN, $CHAT_ID, $document, $caption = '') {
$url = "https://api.telegram.org/bot$TOKEN/sendDocument";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'chat_id' => $CHAT_ID,
'document' => new CURLFile($document['tmp_name'], $document['type'], $document['name']),
'caption' => $caption
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
}
// Sending files to Telegram
if ($attachments['error'] == UPLOAD_ERR_OK) {
sendFile($TOKEN, $CHAT_ID, $attachments,);
}
if ($invoice['error'] == UPLOAD_ERR_OK) {
sendFile($TOKEN, $CHAT_ID, $invoice,);
}
}
?>