Receiving Formdata on gmail on localhost but not via website

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 });
}
"

Hi, @abdulmohiz01!

Have you seen our guide Sending Emails from an application on Vercel? From the guide:

You can also use libraries like nodemailer. When doing so, we recommend using an external host value provided by a third-party provider, rather than defaulting to the outbound SMTP connection of the Serverless Function.

Might be useful!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.