From 95369a5a45cc7dccf3e3c33d9b3d87ebd3710659 Mon Sep 17 00:00:00 2001 From: sasha-astiadi Date: Wed, 19 Jun 2024 18:57:02 +0200 Subject: [PATCH] add email env --- .gitignore | 6 +++- server.js | 59 +++++++++++++++++++++++++++++++++ templates/partials/contact.html | 17 +++------- templates/partials/quote.html | 2 +- 4 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 server.js diff --git a/.gitignore b/.gitignore index 499540b..e5024fd 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,8 @@ run* install* public static/css -tailwindcss \ No newline at end of file +tailwindcss + +# .gitignore +node_modules/ +.env diff --git a/server.js b/server.js new file mode 100644 index 0000000..5ac60fe --- /dev/null +++ b/server.js @@ -0,0 +1,59 @@ +// server.js + +// Load environment variables from .env file +require('dotenv').config(); + +const express = require('express'); +const nodemailer = require('nodemailer'); +const bodyParser = require('body-parser'); + +const app = express(); +const PORT = process.env.PORT || 3000; + +// Middleware to parse JSON and urlencoded form data +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: true })); + +// POST endpoint to handle form submissions +app.post('/api/contact', async (req, res) => { + try { + // Get form data from request body + const { firstName, lastName, email, phoneNumber, message } = req.body; + + // Create transporter for sending emails (replace with your email service details) + const transporter = nodemailer.createTransport({ + service: 'Gmail', + auth: { + user: process.env.EMAIL_USER, // Using environment variable for email user + pass: process.env.EMAIL_PASS // Using environment variable for email password + } + }); + + // Email content + const mailOptions = { + from: process.env.EMAIL_USER, // Replace with your email address + to: 'recipient@example.com', // Replace with recipient email address + subject: 'New Message from Contact Form', + html: ` +

Name: ${firstName} ${lastName}

+

Email: ${email}

+

Phone Number: ${phoneNumber}

+

Message:
${message}

+ ` + }; + + // Send email + await transporter.sendMail(mailOptions); + + // Response back to client + res.status(200).send('Message sent successfully!'); + } catch (error) { + console.error('Error sending email:', error); + res.status(500).send('Error sending message. Please try again later.'); + } +}); + +// Start server +app.listen(PORT, () => { + console.log(`Server is running on http://localhost:${PORT}`); +}); diff --git a/templates/partials/contact.html b/templates/partials/contact.html index c7e3b2a..844838d 100644 --- a/templates/partials/contact.html +++ b/templates/partials/contact.html @@ -14,7 +14,7 @@ -->
-
+

Get in touch

-

Proin volutpat consequat porttitor cras nullam gravida at. Orci molestie a eu arcu. Sed ut tincidunt integer elementum id sem. Arcu sed malesuada et magna.

+

At OurWorld, we value your feedback and inquiries. Whether you're interested in our ventures, have questions about our technologies, or want to collaborate, we're here to connect. Reach out to us today and let's build a better digital future together.

@@ -42,16 +42,7 @@
-
545 Mavis Island
Chicago, IL 99191
-
-
-
- Telephone - -
-
+1 (555) 234-5678
+
Nexus Global Financial Services Limited,
Ebene, Mauritius.
@@ -60,7 +51,7 @@
-
hello@example.com
+
info@ourworld.tf
diff --git a/templates/partials/quote.html b/templates/partials/quote.html index 209ce94..98ee412 100644 --- a/templates/partials/quote.html +++ b/templates/partials/quote.html @@ -1,4 +1,4 @@ -
+