我正在尝试将nodemailer用于表单,以便用户可以向我发送消息。它可以在我的本地端口上运行,但是一旦将网站托管在namecheap中。它根本不发送电子邮件。我想念什么?这是我的代码:
// POST route from contact form
var transporter = nodemailer.createTransport(smtpTransport({
service: 'Gmail',
auth: {
user: process.env.GMAIL_USER,
pass: process.env.GMAIL_PASS
}
}));
app.post('/contact-submit', (req, res) => {
console.log('/contact-submit', req.body)
var mailOptions = {
from: 'danielladevoto@gmail.com',
to: 'danielladevoto@gmail.com',
subject: req.body.subject,
text: req.body.message,
replyTo: req.body.email
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
console.log(req.body);
res.end('Submitted')
});
谢谢!