diff --git a/client/src/App.jsx b/client/src/App.jsx
index 3cbfe4a..e88e54a 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -21,6 +21,7 @@ import AboutPage from "./pages/AboutPage";
import NotFound from "./pages/NotFound";
import FaqWidget from "./components/FaqWidget"; // ✅ merged from feat/faq
+import ContactForm from "./pages/contact";
// Socket connection (change URL as needed)
const socket = io("http://localhost:3000");
@@ -109,6 +110,7 @@ const App = () => {
} />
} />
} />
+ }/>
} />
diff --git a/client/src/pages/Contact.jsx b/client/src/pages/Contact.jsx
new file mode 100644
index 0000000..934a2bb
--- /dev/null
+++ b/client/src/pages/Contact.jsx
@@ -0,0 +1,159 @@
+import React, { useState } from "react";
+import { motion } from "framer-motion";
+
+const ContactForm = () => {
+ const [formData, setFormData] = useState({
+ name: "",
+ email: "",
+ subject: "",
+ message: "",
+ });
+
+ const [status, setStatus] = useState(null);
+
+ const handleChange = (e) => {
+ setFormData({ ...formData, [e.target.name]: e.target.value });
+ };
+
+ const handleSubmit = async (e) => {
+ e.preventDefault();
+
+ try {
+ const res = await fetch("http://localhost:5000/api/auth/send", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(formData),
+ });
+
+ const data = await res.json(); // fetch ke liye yeh zaruri hai
+
+ if (res.ok) {
+ setStatus({ success: true, message: data.success });
+ setFormData({
+ name: "",
+ email: "",
+ subject: "",
+ message: "",
+ });
+ } else {
+ setStatus({ success: false, message: data.error || "Something went wrong!" });
+ }
+ } catch (error) {
+ console.error("Error:", error);
+ setStatus({
+ success: false,
+ message: "Something went wrong!",
+ });
+ }
+};
+
+
+ return (
+ <>
+
+
+
+ >
+ );
+};
+
+export default ContactForm;
diff --git a/server/config/emailConfig.js b/server/config/emailConfig.js
index 57d3167..eccb4ec 100644
--- a/server/config/emailConfig.js
+++ b/server/config/emailConfig.js
@@ -18,7 +18,7 @@ const sendMail = async (to, subject, text, html) => {
from: `"ChatterSpace" <${process.env.EMAIL_USER}>`,
to,
subject,
- text,
+ html:text,
};
await transporter.sendMail(mailOptions);
diff --git a/server/controllers/authController.js b/server/controllers/authController.js
index 1815332..ff9f546 100644
--- a/server/controllers/authController.js
+++ b/server/controllers/authController.js
@@ -288,6 +288,39 @@ const resetPassword = async (req, res) => {
}
+//contactUs
+
+
+const sendContactEmail = async (req, res) => {
+ const { name, email, subject, message } = req.body;
+
+ if (!name || !email || !message) {
+ return res.status(400).json({ error: 'All fields are required' });
+ }
+
+ try {
+ const emailMessage = `
+ New Contact Query
+ Name: ${name}
+ Email: ${email}
+ Message:
+ ${message}
+ `;
+
+ await sendMail(
+ process.env.SMTP_FROM_EMAIL,
+ subject || 'New Query',
+ emailMessage
+ );
+
+ res.status(200).json({ success: 'Email sent successfully!' });
+ } catch (error) {
+ console.error('Error in sending email:', error);
+ res.status(500).json({ error: 'Failed to send email' });
+ }
+};
+
+
module.exports = {
signupUser,
@@ -297,5 +330,6 @@ module.exports = {
getuserbyid,
deleteuser,
forgotPassword,
- resetPassword
+ resetPassword,
+ sendContactEmail
}
diff --git a/server/routes/authRoutes.js b/server/routes/authRoutes.js
index e3940b3..18eb382 100644
--- a/server/routes/authRoutes.js
+++ b/server/routes/authRoutes.js
@@ -21,5 +21,7 @@ router.delete("/delete/:id",authController.deleteuser);
// ⬅️ Add this new route for forgot password
router.post('/forgotpassword', authController.forgotPassword);
+//contactUs
+router.post('/send', authController.sendContactEmail);
module.exports = router;