From f0fafe61b71f38c4c0711f6a137f38d83cec4281 Mon Sep 17 00:00:00 2001 From: MaxNadeev Date: Fri, 22 Mar 2024 23:14:17 +0300 Subject: [PATCH] php script that sends emails --- .htaccess | 3 + .vscode/launch.json | 15 ----- amvera/dockerfile/amvera.yml | 12 ---- index.html | 26 +++++--- index.js | 59 ------------------- mail.php | 42 +++++++++++++ scripts/script.js | 111 +++++++++++++++++++++-------------- style.css | 4 ++ 8 files changed, 135 insertions(+), 137 deletions(-) create mode 100644 .htaccess delete mode 100644 .vscode/launch.json delete mode 100644 amvera/dockerfile/amvera.yml delete mode 100644 index.js create mode 100644 mail.php diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..b6f3700 --- /dev/null +++ b/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine On +RewriteCond %{SERVER_PORT} !^443$ +RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 6602f2f..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - - { - "type": "msedge", - "request": "launch", - "name": "Open index.html", - "file": "e:\\Projects\\sochisto\\index.html" - } - ] -} \ No newline at end of file diff --git a/amvera/dockerfile/amvera.yml b/amvera/dockerfile/amvera.yml deleted file mode 100644 index eff662e..0000000 --- a/amvera/dockerfile/amvera.yml +++ /dev/null @@ -1,12 +0,0 @@ -meta: - environment: node - toolchain: - name: npm - version: 18 -build: - artifacts: - '*': / - command: dev -run: - persistenceMount: /data - containerPort: 80 diff --git a/index.html b/index.html index 51557eb..e91bb27 100644 --- a/index.html +++ b/index.html @@ -5,8 +5,8 @@ - - + + Сочисто! | Уборка квартир в Сочи @@ -75,9 +75,6 @@

Оставьте заявку

-

- Спасибо -

Мы свяжемся с вами в самое ближайшее время для уточнения деталей и записи на уборку.

@@ -90,11 +87,26 @@

Вы сможете узнать всю необходимую информацию и забронировать время уборки.

-
+ + + + + + + + + + + + +
-
+
Перезвоните мне
diff --git a/index.js b/index.js deleted file mode 100644 index efe2b51..0000000 --- a/index.js +++ /dev/null @@ -1,59 +0,0 @@ -const http = require('http'); -const TelegramApi = require('node-telegram-bot-api') -const dotenv = require('dotenv') - -dotenv.config() -const token = process.env.TG_TOKEN -const usr = process.env.USER_ID - -const bot = new TelegramApi(token, {polling: true}) - -bot.on('message', msg => { - const text = msg.text; - const chatId = msg.chat.id.toString(); - const firstName = msg.chat.first_name; - - console.log(text, chatId, usr) - - if (text === '/start' && chatId === usr) { - bot.sendMessage(chatId, `Добро пожаловать, ${firstName}`) - } - - console.log(msg) -}) - -const server = http.createServer((req, res) => { - // Allow requests from any origin - res.setHeader('Access-Control-Allow-Origin', '*'); - // Allow the methods 'POST' - res.setHeader('Access-Control-Allow-Methods', 'POST'); - // Allow the headers 'Content-Type' - res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); - - if (req.method === 'OPTIONS') { - res.writeHead(200); - res.end(); - return; - } - - if (req.method === 'POST' && req.url === '/sendData') { - let data = ''; - req.on('data', chunk => { - data += chunk; - }); - - req.on('end', () => { - const jsonData = JSON.parse(data); - const { name, phone } = jsonData; - console.log(`Received data from frontend: \n\n${name} \n${phone}`); - bot.sendMessage(usr, `На сайте новая заявка: \n\n${name} \n${phone}`) - res.writeHead(200, { 'Content-Type': 'text/plain' }); - res.end('Data received by Node.js'); - }); - } -}); - -server.listen(3000, '127.0.0.1', () => { - console.log('Server running at http://127.0.0.1:3000/'); -}); - diff --git a/mail.php b/mail.php new file mode 100644 index 0000000..f5d569d --- /dev/null +++ b/mail.php @@ -0,0 +1,42 @@ + \ No newline at end of file diff --git a/scripts/script.js b/scripts/script.js index 407a4e8..1e85cce 100644 --- a/scripts/script.js +++ b/scripts/script.js @@ -46,39 +46,35 @@ function checkRadio(elementId) { scrollToFilters(); } -document.getElementById('submit').addEventListener('click', function() { - const name = document.getElementById('name').value; - const phone = document.getElementById('phone').value; - - if (name.trim() === '') { - console.log('Please fill out NAME!'); - document.getElementById('name').style.border = '2px solid red' - return; - } - if (phone.trim() === '') { - console.log('Please fill out PHONE!'); - document.getElementById('phone').style.border = '2px solid red' - return; - } - else { - - const dataToSend = { - name: name, - phone: phone - } - - sendDataToNode(dataToSend); - document.getElementById('name').disabled = true; - document.getElementById('phone').disabled = true; +document.querySelectorAll('.clientForm').forEach( (e) => { + document.getElementById('submit').addEventListener('click', function() { + const name = document.getElementById('name').value; + const phone = document.getElementById('phone').value; - document.getElementById('name').value = ''; - 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); + - document.getElementById('hide-after-success').style.display = 'none'; - document.getElementById('success').style.display = 'block'; - }; -}); + }; + }) +}) document.getElementById('again').addEventListener('click', function() { console.log('again click'); @@ -88,18 +84,45 @@ document.getElementById('again').addEventListener('click', function() { document.getElementById('success').style.display = 'none'; }) -function sendDataToNode(data) { - fetch('http://localhost:3000/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); - }); +function showSuccess(){ + document.getElementById('name').disabled = true; + document.getElementById('phone').disabled = true; + + document.getElementById('name').value = ''; + document.getElementById('phone').value = ''; + + document.getElementById('hide-after-success').style.display = 'none'; + document.getElementById('success').style.display = 'block'; } + +function sendEmail(dataToSend){ + const mailPath = '../mail.php' + let request = new XMLHttpRequest(); + var params = JSON.stringify(dataToSend); + + request.open('POST', mailPath, true) + request.setRequestHeader('Content-Type', 'application/json'); + request.send(params); + request.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + 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); +// }); +// }; diff --git a/style.css b/style.css index 15fba88..8410e8e 100644 --- a/style.css +++ b/style.css @@ -139,6 +139,10 @@ p{ margin-top: var(--general-margin); } +#name{ + margin-top: 0; +} + :focus::-webkit-input-placeholder { color: transparent; }