我有一个表单,我使用nodemailer向自己发送测试邮件
在"到"和"主题"我希望将用户输入的电子邮件放入表单中,当用户点击提交时,它会向他们发送电子邮件。我已经尝试req.email
和req.body.email
并且没有成功。
app.get("/teachers/payment", function (req, res) {
res.render("teacher_payment.ejs")
});
app.post("/registration", function (req, res) {
var transporter = nodemailer.createTransport({
service: 'Gmail'
, auth: {
user: 'user'
, pass: 'pass'
}
});
var mailOptions = {
from: 'zyyangch@gmail.com'
, to: 'req.body.email'
, subject: req.body.email
, text: 'It works! ✔', //plaintext body
html: '<a href="http://localhost:3000/complete-profile">Click Here</a>'
};
//send mail with defined transport object
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
}
else {
console.log('Message sent: ' + info.response);
}
});
})
对此有何解决方法?
答案 0 :(得分:1)
您需要从电子邮件密钥中获取值,不带引号:
var mailOptions = {
from: 'zyyangch@gmail.com'
, to: req.body.email
, subject: req.body.email
, text: 'It works! ✔', //plaintext body
html: '<a href="http://localhost:3000/complete-profile">Click Here</a>'
};