Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Contact Us #124

Open
wants to merge 5 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"mongoose": "^8.2.1",
"next": "^14.1.0",
"next-sitemap": "^4.2.3",
"node-mailer": "^0.1.1",
"react": "^18",
"react-confetti": "^6.1.0",
"react-dom": "^18",
Expand Down
30 changes: 17 additions & 13 deletions pages/api/v1/contact/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import Contact from "@/utils/models/contact.model";
import DBInstance from "@/utils/db";
DBInstance();
import { sendmail } from "./nodemailer";

export default async function handler(req, res) {
if (req.method === "POST") {
try {
const { name, email, message } = req.body;

const contact = new Contact({
if (!name || !email || !message) {
return res
.status(400)
.json({ message: "All fields are required" });
}

console.log("Received contact form data:", {
name,
email,
message
});

await contact.save();
const emailResponse = await sendmail(name, email, message);

res.status(200).json({ message: "Message sent successfully" });
if (emailResponse.success) {
return res.status(200).json({ message: emailResponse.message });
} else {
return res.status(500).json({ message: emailResponse.message });
}
} catch (error) {
console.error(error, res, "INTERNAL_SERVER_ERROR");
console.error("Error processing request:", error);
return res.status(500).json({ message: "Internal server error" });
}
} else {
console.log("🚫", req.method, "was called and got an error!");
res.status(405).json({
success: false,
data: null,
message: "🚫 HTTP Method not Allowed"
});
res.status(405).json({ message: "Method not allowed" });
}
}
34 changes: 34 additions & 0 deletions pages/api/v1/contact/nodemailer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import nodemailer from "nodemailer";

export const sendmail = async (name, email, query) => {
try {
const transporter = nodemailer.createTransport({
host: "smtp.zoho.in",
port: 465,
secure: true,
auth: {
user: process.env.SENDER_EMAIL, // Club Query Zoho email
pass: process.env.SENDER_PASS
}
});

const mailOptions = {
from: process.env.SENDER_EMAIL,
to: process.env.RECIPIENT_EMAIL, // Club community email address
subject: `Query from ${email}`,
html: `Hello Support Team,<br><br>
Please find below a new inquiry from <br>Name: <strong>${name}</strong><br>Email: <em>${email}</em>.<br><br>
<strong>Query:</strong><br>
${query}<br><br>
Kind regards,<br>
${name}`
Fixed Show fixed Hide fixed
};

const info = await transporter.sendMail(mailOptions);
console.log("Email sent successfully:", info.response);
return { success: true, message: "Email sent successfully" };
} catch (err) {
console.error("Error sending email:", err.message);
return { success: false, message: err.message };
}
};
14 changes: 7 additions & 7 deletions public/sitemap-0.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url><loc>https://githubsrmist.tech</loc><lastmod>2024-11-08T19:21:29.955Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech/about</loc><lastmod>2024-11-08T19:21:29.955Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech/contact</loc><lastmod>2024-11-08T19:21:29.955Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech/events</loc><lastmod>2024-11-08T19:21:29.955Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech/recruitment</loc><lastmod>2024-11-08T19:21:29.955Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech/recruitment/dashboard</loc><lastmod>2024-11-08T19:21:29.955Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech/team</loc><lastmod>2024-11-08T19:21:29.955Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech</loc><lastmod>2024-11-14T06:24:31.549Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech/about</loc><lastmod>2024-11-14T06:24:31.551Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech/contact</loc><lastmod>2024-11-14T06:24:31.551Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech/events</loc><lastmod>2024-11-14T06:24:31.551Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech/recruitment</loc><lastmod>2024-11-14T06:24:31.551Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech/recruitment/dashboard</loc><lastmod>2024-11-14T06:24:31.551Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://githubsrmist.tech/team</loc><lastmod>2024-11-14T06:24:31.551Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
</urlset>
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4480,11 +4480,23 @@ next@^14.1.0:
"@next/swc-win32-ia32-msvc" "14.2.5"
"@next/swc-win32-x64-msvc" "14.2.5"

node-mailer@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/node-mailer/-/node-mailer-0.1.1.tgz#609e14a9b2c34422540b3a66938163d1d2421500"
integrity sha512-L3YwTtPodsYr1sNPW/PxXw0rSOr/ldygaIph2YtXDwLGt9l8km/OjM0Wrr57Yf07JEEnDb3wApjhVdR0k5v0kw==
dependencies:
nodemailer ">= 0.1.15"

node-releases@^2.0.18:
version "2.0.18"
resolved "https://registry.npmjs.org/node-releases/-/node-releases-2.0.18.tgz"
integrity sha512-d9VeXT4SJ7ZeOqGX6R5EM022wpL+eWPooLI+5UpWn2jCT1aosUQEhQP214x33Wkwx3JQMvIm+tIoVOdodFS40g==

"nodemailer@>= 0.1.15":
version "6.9.16"
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.9.16.tgz#3ebdf6c6f477c571c0facb0727b33892635e0b8b"
integrity sha512-psAuZdTIRN08HKVd/E8ObdV6NO7NTBY3KsC30F7M4H1OnmLCUNaS56FpYxyb26zWLSyYF9Ozch9KYHhHegsiOQ==

normalize-path@^3.0.0, normalize-path@~3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz"
Expand Down