I'm doing an app with React/NodeJS,
In the app, there's the Contact Page with a form with 3 input fields : email, object and message, In the email field, the user puts his email address to be contacted later by the recipient (me), I succeeded to send the mail and the object on my email address,but in the sender space of my Gmail I get my mail and not the mail from the input field,
How can I get the mail from the sender in the mail ?
Here's my code :
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: `${process.env.EMAIL_ADDRESS}`,
pass: `${process.env.EMAIL_PASSWORD}`,
},
});
const mailOptions = {
from: formValues.email, <-- HERE I HAVE THE MAIL OF THE SENDER, BUT CAN NEVER SEE IT IN THE EMAIL
to: process.env.EMAIL_ADDRESS,
subject: `Contact form - ${formValues.object}`,
text: formValues.message,
};
transporter.sendMail(mailOptions, (err, response) => {
if (err) {
console.error("err ", err);
} else {
res.status(200).json({ message: "Email sent" });
}
});
You can see in the picture that instead of getting the email of the sender, I have my email in both sender and recipients https://ibb.co/rxNHGnP
I don't think that is possible, the sender field represent the address that is trying to send the email (the one who logged in) which in this case it's you. That's why you are seeing sender as your email address as you are sending an email from yourself to yourself. You can only add the formValues data to the recipient (to) field of mailOption.