Reputation: 169
I have a field called email in html page. I am getting this email from there by using req.body.e
and i want to send some particular mails to this address(dynamic,whoever enter his email address mail is sent to his email). Only problem i am facing is i dont know what to write in " to:
" in code.
app.post('/mail', (request, response) => {
var e = request.body.e;
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'uni9039'
}
});
var mailOptions = {
from: '[email protected]',
to: 'e' ,
subject: 'Testing',
text: `Only test`
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
})
This is html field
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" name="e" placeholder="Enter email" name="email">
</div>
In this code i am getting this error.
Upvotes: 0
Views: 1309
Reputation: 7685
Assuming that the input value is submitted as a regular form, you need to parse request body content with the appropriate middleware on Node.js side:
const express = require('express');
app.use(express.urlencoded());
app.post('/mail', (request, response) => {
var e = request.body.e;
console.log(e);
// ...the rest of code
Upvotes: 1