Skip to content

Commit c64f9f6

Browse files
Merge pull request #119 from deveshsawant05/new
Added Email functionality to Contact Us Page
2 parents ca5db7b + c077223 commit c64f9f6

File tree

4 files changed

+264
-132
lines changed

4 files changed

+264
-132
lines changed

package-lock.json

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"next": "14.2.5",
3838
"next-client-cookies": "^1.1.1",
3939
"next-sitemap": "^4.2.3",
40+
"nodemailer": "^6.9.15",
4041
"react": "^18",
4142
"react-dom": "^18",
4243
"react-icons": "^5.2.1",

src/app/api/sendEmail/route.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { NextRequest, NextResponse } from 'next/server';
2+
import nodemailer from 'nodemailer';
3+
4+
export async function POST(req) {
5+
try {
6+
const body = await req.json();
7+
const { name, email, message, contact, organisation, messageType } = body;
8+
console.log(messageType);
9+
10+
// Determine if it's a bug or a message
11+
const typeTitle = messageType==="Message" ? 'Message from User': 'Bug Report from User';
12+
const typeMessage = messageType==="Message" ? 'Message' : 'Message/Issue';
13+
14+
const transporter = nodemailer.createTransport({
15+
service: 'gmail',
16+
auth: {
17+
user: process.env.EMAIL_USER,
18+
pass: process.env.EMAIL_PASSWORD,
19+
},
20+
});
21+
22+
const htmlContent = `
23+
<div style="background-color:#f4f4f4;padding:20px;">
24+
<div style="max-width:600px;margin:auto;background-color:white;padding:20px;border-radius:10px;box-shadow:0 4px 8px rgba(0, 0, 0, 0.1);">
25+
<p style="margin-top: 20px; font-size: 12px; color: #777;">
26+
This message was sent via the <strong>IIITV Coding Club Website</strong>.
27+
</p>
28+
<h1 style="background-color:#f88474;color:white;padding:10px;border-top-left-radius:10px;border-top-right-radius:10px;">${typeTitle}</h1>
29+
<p><strong>Name:</strong> ${name}</p>
30+
<p><strong>Email:</strong> ${email}</p>
31+
<p><strong>Contact No.:</strong> ${contact}</p>
32+
<p><strong>Organisation:</strong> ${organisation}</p>
33+
<div style="background-color:#f9f9f9;padding:10px;border-radius:8px;margin:10px 0;">
34+
<p><strong>${typeMessage}:</strong></p>
35+
<p>${message}</p>
36+
</div>
37+
<a href="mailto:${email}" style="display:inline-block;background-color:#f88474;color:white;padding:5px 20px;border-radius:8px;text-decoration:none;margin-top:20px;">Reply to User</a>
38+
</div>
39+
</div>
40+
`;
41+
42+
const mailOptions = {
43+
from: email,
44+
45+
subject: `${typeTitle}: ${name}`,
46+
html: htmlContent,
47+
};
48+
49+
await transporter.sendMail(mailOptions);
50+
51+
return NextResponse.json({ success: true, message: 'Email sent successfully' });
52+
} catch (error) {
53+
console.error('❌ Error sending email:', error);
54+
return NextResponse.json({ success: false, message: 'Failed to send email', error: error.message }, { status: 500 });
55+
}
56+
}

0 commit comments

Comments
 (0)