Skip to content

Commit

Permalink
add ContactUs Page
Browse files Browse the repository at this point in the history
  • Loading branch information
PriyanshuValiya committed Oct 25, 2024
1 parent 61e3a24 commit 77cf18e
Show file tree
Hide file tree
Showing 4 changed files with 550 additions and 333 deletions.
49 changes: 49 additions & 0 deletions backend/controllers/contactusController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import nodemailer from "nodemailer";
import "dotenv/config";

export const createContactUs = async (req, res) => {
const { mail, subject, message } = req.body;

try {
const transporter = nodemailer.createTransport({
service: "gmail",
host: "smtp.gmail.com",
port: 587,
secure: false,
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
tls: {
rejectUnauthorized: false, // Disable strict SSL verification
},
});

const mailOptions = {
from: mail,
to: process.env.EMAIL_USER,
subject: subject,
text: message,
};

// Send mail with defined transport object
transporter.sendMail(mailOptions, (error, mailOptions) => {
if (error) {
console.error("Error occurred: " + error.message);
return;
}
});

res.status(200).json({
status: "success",
message: "Your contact request has been successfully received.",
});
} catch (err) {
console.error(`Error at transport : ${err}`);
res.status(500).json({
status: "error",
message:
"There was an error sending your message. Please try again later.",
});
}
};
3 changes: 2 additions & 1 deletion backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ connectDB();
import authRoutes from "./routes/authRoutes.js";
import stationRoutes from "./routes/stationRoutes.js";
import trainRoutes from "./routes/trainRoutes.js";
import contactUs from "./routes/contactUsRouter.js";

app.use("/auth", authRoutes);
app.use("/api", authRoutes);
app.use("/station", stationRoutes);
app.use("/train", trainRoutes);

app.use("/contact", contactUs);


app.get("/", (req, res) => {
Expand Down
7 changes: 7 additions & 0 deletions backend/routes/contactUsRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import express from 'express';
const router = express.Router();
import { createContactUs } from "../controllers/contactusController.js";

router.post("/contactus", createContactUs);

export default router;
Loading

0 comments on commit 77cf18e

Please sign in to comment.