Skip to content

Commit

Permalink
send form data to email and telegram bot
Browse files Browse the repository at this point in the history
function sendTelegram added 1

function sendTelegram added

file_get_contents 14

file_get_contents 13

file_get_contents 12

file_get_contents 11

file_get_contents 11

file_get_contents 10

file_get_contents 9

file_get_contents 8

file_get_contents 7

file_get_contents 6

file_get_contents 5

file_get_contents 4

file_get_contents 3

file_get_contents 2

file_get_contents 1

file_get_contents

string concatination

function send to telegram

new token

message in function 1

message in function

added consts

tests 454647

45

consts file init

consts file init

ver stable 1.0

telegram bot api strings

telegram bot in php

test with argv

cgi use init

disabled email send for tests

line 57 forgottenn comma

bot.py bot connected

curl global url

curl result

curl error show

relative link in curl function

sending with cURL

python script listens post message
  • Loading branch information
MaxNadeev committed Mar 27, 2024
1 parent f0fafe6 commit 6def027
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 51 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
sochisto.zip
.env
/node_modules
/.vscode
package-lock.json
package.json
consts.txt
3 changes: 3 additions & 0 deletions consts.txt.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
your_telegram_token_from_bot_father
your_telegram_id
developer_telegram_id
19 changes: 1 addition & 18 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<noscript><div><img src="https://mc.yandex.ru/watch/96480520" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<link rel="stylesheet" href="style.css?version=10">
<script src="scripts/script.js?version=12" defer></script>
<script src="scripts/script.js?version=13" defer></script>
<script src="./scripts/prices.js" defer></script>
<title>Сочисто! | Уборка квартир в Сочи</title>
<link rel="icon" href="img/favicon.jpg">
Expand Down Expand Up @@ -87,22 +87,7 @@ <h1 class="text-accent">Оставьте заявку</h1>
<p class="text">
Вы сможете узнать всю необходимую информацию и забронировать время уборки.
</p>

<!-- <form enctype="multipart/form-data" action="/settings/uploadFile" method="post" class="dropzone" id="my-awesome-dropzone">
<input type="text" name="x" value="kittens">
<input type="text" name="y" value="puppies">
</form> -->


<form class="clientForm" enctype="multipart/form-data" action="mail.php" method="post">

<!-- Hidden Required Fields -->
<input type="hidden" name="project_name" value="Сочисто">
<input type="hidden" name="admin_email" value="[email protected]">
<input type="hidden" name="form_subject" value="Новая заявка на сайте">
<!-- END Hidden Required Fields -->


<input class="text input" type="text" id="name" name="name" placeholder="Ваше имя" required>
<input class="text input" type="tel" id="phone" name="phone" placeholder="Ваш телефон" required>
<div class="after-list">
Expand All @@ -112,8 +97,6 @@ <h1 class="text-accent">Оставьте заявку</h1>
</div>
</form>
</div>


</div>
</div>
<div id="services" class="container">
Expand Down
32 changes: 4 additions & 28 deletions scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,24 @@ document.querySelectorAll('.clientForm').forEach( (e) => {
const phone = document.getElementById('phone').value;

if (name.trim() === '') {
//Please fill out NAME!
document.getElementById('name').style.border = '2px solid red'
return;
}
if (phone.trim() === '') {
//Please fill out PHONE!
document.getElementById('phone').style.border = '2px solid red'
return;
}
else {

const dataToSend = {
name: name,
phone: phone
}
sendEmail(dataToSend)
// sendDataToNode(dataToSend);


send(dataToSend)
};
})
})

document.getElementById('again').addEventListener('click', function() {
console.log('again click');
document.getElementById('name').disabled = false;
document.getElementById('phone').disabled = false;
document.getElementById('hide-after-success').style.display = 'block';
Expand All @@ -95,8 +88,8 @@ function showSuccess(){
document.getElementById('success').style.display = 'block';
}

function sendEmail(dataToSend){
const mailPath = '../mail.php'
function send(dataToSend){
const mailPath = '../sender.php'
let request = new XMLHttpRequest();
var params = JSON.stringify(dataToSend);

Expand All @@ -108,21 +101,4 @@ function sendEmail(dataToSend){
showSuccess();
}
}
}

// function sendDataToNode(data) {
// // fetch('https://sochisto-bot-lizatravel.amvera.io:80/sendData', {
// fetch('95.26.169.129:80/sendData', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify(data)
// })
// .then(response => {
// console.log('Data sent to Node.js');
// })
// .catch(error => {
// console.error('Error sending data:', error);
// });
// };
}
22 changes: 21 additions & 1 deletion mail.php → sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,25 @@
echo "Email успешно отправлен 📧";
} else {
echo "Что-то пошло не так при отправке письма 🙁";
}
};

$conststxt = file_get_contents('consts.txt');
$consts = explode("\n", $conststxt);

$apiToken = substr($consts[0], 0, -1);
$owner = $consts[1];
$dev = $consts[2];

function sendTelegram($chat_id, $message, $apiToken) {
$data = [
'chat_id' => $chat_id,
'text' => $message,
'parse_mode' => 'HTML'
];
$response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?".http_build_query($data));
};

sendTelegram($owner, $message, $apiToken);
sendTelegram($dev, $message, $apiToken);

?>

0 comments on commit 6def027

Please sign in to comment.