New here :)
So I'm working on a React app and this is literally the last thing that I'm supposed to do but I can't for the life of me find a solution. We've hosted the app on BlueHost and there's a small API for sending emails but the request never reaches the server (despite working on localhost). I've set fetch to a relative path, included a modified .htaccess file (also found on stack overflow) and fetch always gives me a 200 status, but the request never reaches the server. Here's the relevant front/backend code
let handleSeekerSubmit = async(e) => {
e.preventDefault();
const data = new FormData();
data.append('firstName', seekerFname);
data.append('lastName', seekerLname);
data.append('email', seekerEmail);
data.append('phone', seekerPhone);
data.append('position', seekerPosit)
data.append('cv', seekerCvFile);
try {
let res = await fetch('/seeker_mail', {
method: 'POST',
body: data,
});
if(res.status === 200) {
setSeekerFname("");
setSeekerLname("");
setSeekerEmail("");
setSeekerPhone("");
setSeekerPosit("");
setSeekerCvFile([]);
fileInput.current.value = "";
console.log(res);
}
console.log(res);
} catch(err) {
console.log(err);
}
}
And the backend code:
app.post('/seeker_mail', cors(), upload.single('cv'), (req, res, next) => {
let {firstName, lastName, email, phone, position, cv } = req.body;
console.log(req.body);
console.log(req);
const transport = nodemailer.createTransport({
host: // hostname,
name: // name,
port: 465,
auth: {
user: process.env.MAIL_USER,
pass: process.env.MAIL_PASS
},
})
transport.sendMail({
from: email,
to: process.env.MAIL_TO,
subject: `${firstName} ${lastName}`,
html: `<div className="email">
<h1>${firstName} ${lastName}</h1>
<p><b>MAIL:</b> ${email}</p>
<p><b>PHONE:</b> ${phone}</p>
<p><b>ROLE:</b> ${position}</p>
</div>`,
attachments: [
{
filename: req.file.originalname,
path: req.file.path
}
]
});
res.sendStatus(200);
});
app.listen(process.env.PORT || 4000, () => {
console.log("Server is listening on port 4000");
})
Now I'm pretty sure it's something obvious that I'm not doing right but also I think it's because NodeJS does not come with Bluehost/cPanel and I have to install it manually somehow...
Anyway thanks for the help and sorry if I'm missing something very obvious or misunderstanding some basic concepts :)
Most likely it's due to not reaching the backend through port 4000.
https://www.bluehost.com/hosting/help/405
You will require a dedicated IP and request the port opened in order to make this work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.