-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (40 loc) · 1.53 KB
/
server.js
File metadata and controls
49 lines (40 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
// Route to serve the form
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
// POST route to handle form submission
app.post('/send-email', async (req, res) => {
const { name, email, message } = req.body;
console.log('Form received:', { name, email, message });
try {
// =====================================================
// TASK FOR RESEARCH PARTICIPANT:
// 1. Configure the Email Provider here.
// 2. Send an email to info@YOUR_DOMAIN.com containing the message.
// 3. Send a confirmation email to the user (req.body.email).
// =====================================================
// TODO: Add Email Sending Logic Here
// Mock success response
res.status(200).send(`
<h1>Success!</h1>
<p>Thanks ${name}. We received your message: "${message}"</p>
<p>A confirmation email has been sent to ${email}.</p>
<a href="/">Go back</a>
`);
} catch (error) {
console.error(error);
res.status(500).send('Error sending emails.');
}
});
app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});