Skip to content

Commit

Permalink
Merge pull request #119 from deveshsawant05/new
Browse files Browse the repository at this point in the history
Added Email functionality to Contact Us Page
  • Loading branch information
Anas-github-acc authored Oct 22, 2024
2 parents ca5db7b + c077223 commit c64f9f6
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 132 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"next": "14.2.5",
"next-client-cookies": "^1.1.1",
"next-sitemap": "^4.2.3",
"nodemailer": "^6.9.15",
"react": "^18",
"react-dom": "^18",
"react-icons": "^5.2.1",
Expand Down
56 changes: 56 additions & 0 deletions src/app/api/sendEmail/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { NextRequest, NextResponse } from 'next/server';
import nodemailer from 'nodemailer';

export async function POST(req) {
try {
const body = await req.json();
const { name, email, message, contact, organisation, messageType } = body;
console.log(messageType);

// Determine if it's a bug or a message
const typeTitle = messageType==="Message" ? 'Message from User': 'Bug Report from User';
const typeMessage = messageType==="Message" ? 'Message' : 'Message/Issue';

const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASSWORD,
},
});

const htmlContent = `
<div style="background-color:#f4f4f4;padding:20px;">
<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);">
<p style="margin-top: 20px; font-size: 12px; color: #777;">
This message was sent via the <strong>IIITV Coding Club Website</strong>.
</p>
<h1 style="background-color:#f88474;color:white;padding:10px;border-top-left-radius:10px;border-top-right-radius:10px;">${typeTitle}</h1>
<p><strong>Name:</strong> ${name}</p>
<p><strong>Email:</strong> ${email}</p>
<p><strong>Contact No.:</strong> ${contact}</p>
<p><strong>Organisation:</strong> ${organisation}</p>
<div style="background-color:#f9f9f9;padding:10px;border-radius:8px;margin:10px 0;">
<p><strong>${typeMessage}:</strong></p>
<p>${message}</p>
</div>
<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>
</div>
</div>
`;

const mailOptions = {
from: email,
to: '[email protected]',
subject: `${typeTitle}: ${name}`,
html: htmlContent,
};

await transporter.sendMail(mailOptions);

return NextResponse.json({ success: true, message: 'Email sent successfully' });
} catch (error) {
console.error('❌ Error sending email:', error);
return NextResponse.json({ success: false, message: 'Failed to send email', error: error.message }, { status: 500 });
}
}
Loading

1 comment on commit c64f9f6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for iiitvcc ready!

✅ Preview
https://iiitvcc-72rv903nx-iiitv-coding-clubs-projects.vercel.app

Built with commit c64f9f6.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.