Trying to set up a contact form using nodemailer. Here is what in my app.js:
// EMail configuration var smtpTransport = nodemailer.createTransport("SMTP",{ service: "Gmail", auth: { user: "myemailaddress", pass: "xxx" } }); // CONTACT FORM app.get('/contact', function (req, res) { res.render("contact"); }); app.post('/contact', function (req, res) { var mailOptions = { from: req.body.email, // sender address to: "myemailaddress", // list of receivers subject: req.body.subject, // Subject line text: req.body.message, // plaintext body } smtpTransport.sendMail(mailOptions, function(error, response){ if(error){ console.log(error); }else{ console.log("Message sent: " + response.message); } smtpTransport.close(); // shut down the connection pool, no more messages }); res.render("contact", { success: "building web app" }); });
And my contact.jade template is as follows:
form#contact-form(action="/contact", method="POST") div.span5 p Full name: input#name(type="text", name="name") p Email address: input#email(type="email", name="email") p Subject: input#subject(type="text", name="subject") p Message: textarea#message(type="text", name="message", rows="5") p: button(type="submit") Send message
Now the email works, but it comes from myemailaddress, and not from the one that I enter in the email field in the template. Any ideas
source share