Hi,
I’m using nodemailer to send form data to my gmail. When I submit it via localhost, I receive it on my gmail but when i host it, the response is 200 but I dont receive any on my gmail app. Im using my one email to send to another email which’s also mine.
Can someone please tell what’s the issue and how to solve it? I’m using next.js 14.
For reference, here’s the link to the website: www.nexusencryption.com and here’s my code:
"
import nodemailer from ‘nodemailer’
import { NextResponse } from ‘next/server’;
export async function POST(request) {
try {
const data = await request.json();
// console.log(data);
const { name, email, subject, message } = data;
const transporter = nodemailer.createTransport({
service: ‘gmail’,
auth: {
user: process.env.emailFrom,
pass: process.env.pass,
},
});
const mailOptions = {
from: process.env.emailFrom,
to: process.env.emailTo,
subject: ${subject}
,
text: Name: ${name} \nEmail: ${email}\n\nMessage: ${message}
,
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error);
res.status(500).send(‘Internal Server Error’);
}
else {
console.log('Email Sent: ’ + info.response);
}
});
return NextResponse.json({ message: 'Data received successfully' }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ message: ‘Error processing request’ }, { status: 500 });
}
}
export async function GET(request) {
return NextResponse.json({ message: ‘This is a GET request’ }, { status: 200 });
}
"