diff --git a/backend/server.js b/backend/server.js index d3e2650..3a9d13f 100644 --- a/backend/server.js +++ b/backend/server.js @@ -2,6 +2,7 @@ const express = require('express'); const fs = require('fs'); const path = require('path'); const bodyParser = require('body-parser'); +const nodemailer = require('nodemailer'); const app = express(); const PORT = process.env.PORT || 3000; @@ -27,9 +28,30 @@ app.post('/contact', (req, res) => { return res.status(400).json({ error: 'All fields are required' }); } - // Here you can add code to save the contact form data to a database or send an email + // Create a transporter object using the default SMTP transport + const transporter = nodemailer.createTransport({ + service: 'gmail', + auth: { + user: 'your-email@gmail.com', + pass: 'your-email-password' + } + }); + + // Set up email data + const mailOptions = { + from: email, + to: 'your-email@gmail.com', + subject: 'New Contact Form Submission', + text: `Name: ${name}\nEmail: ${email}\nMessage: ${message}` + }; - res.json({ success: 'Contact form submitted successfully' }); + // Send email + transporter.sendMail(mailOptions, (error, info) => { + if (error) { + return res.status(500).json({ error: 'Failed to send email' }); + } + res.json({ success: 'Contact form submitted successfully' }); + }); }); app.listen(PORT, () => { diff --git a/docs/README.md b/docs/README.md index 38f359b..569bacb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,6 +6,7 @@ A beautiful, responsive website for keto recipes with: - Mobile-friendly design - Countdown timer - Testimonials section +- Contact form functionality ## Deployment 1. Upload to GitHub @@ -20,3 +21,6 @@ A beautiful, responsive website for keto recipes with: 4. Run `npm install` to install dependencies 5. Run `npm start` to start the backend server 6. The backend API will be available at `http://localhost:3000` + +## Contact Form +The website includes a contact form on the `index.html` and `about.html` pages. The form allows users to submit their name, email, and message. The form data is sent to the backend API, which handles the submission by sending an email with the form details. diff --git a/docs/about.html b/docs/about.html index 88476f5..775594a 100644 --- a/docs/about.html +++ b/docs/about.html @@ -185,6 +185,30 @@