PHP form and Telegram API

Soul Rest

I made a PHP code using telegram API. Code have to take value from html contact form (action=”telegram.php”) and put it to .vcf file (VCard) and send it to group in telegram. But if I send form, in chat comes a message “Resource Id”. Please tell me where I was wrong?

'<!--?php
$name = $_POST['user_name'];
$phone = $_POST['user_phone'];
$email = $_POST['user_email'];
$token = "token";
$chat_id = "chat";
$arr = array( 'Имя пользователя: ' =--> $name, 'Телефон: ' => $phone, 'Email' => $email
);
foreach($arr as $key => $value) { $txt .= "<b>".$key."</b> ".$value."%0A";
};
$fp = fopen("file.vcf","w");
fwrite($fp, $txt);
$sendToTelegram = fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$fp}","r");
if ($sendToTelegram) { header('Location: index.html');
} else { echo "Error";
}
?>`
1 ответ

Soul Rest

http://php.net/manual/ru/function.fopen.php Вы передаёте в телеграм указатель на файл, а не файл. Для передачи файла нужно использовать - https://core.telegram.org/bots/api#senddocument

licensed under cc by-sa 3.0 with attribution.