Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var nodemailer = require('nodemailer');
- var bodyParser = require('body-parser');
- var express = require('express');
- var app = express();
- app.use(bodyParser.urlencoded({ extended: true }));
- app.post('/contact', function (req, res) {
- var mailOpts, smtpConfig;
- //Setup Nodemailer transport, I chose gmail. Create an application-specific password to avoid problems.
- smtpConfig = nodemailer.createTransport('SMTP', {
- service: 'Gmail',
- auth: {
- user: "g.campbell269@gmail.com",
- pass: "102193gc"
- }
- });
- //Mail options
- mailOpts = {
- from: req.query.name + ' <' + req.query.email + '>', //grab form data from the request body object
- to: 'g.campbell269@gmail.com',
- subject: 'Website contact form',
- text: req.query.message
- };
- smtpConfig.sendMail(mailOpts, function (error, response) {
- //Email not sent
- if (error) {
- res.end("Email send failed");
- //res.render('contact', { title: 'Raging Flame Laboratory - Contact', msg: 'Error occured, message not sent.', err: true, page: 'contact' })
- //console.log("error");
- }
- //Yay!! Email sent
- else {
- res.end("Email send successfully");
- //res.render('contact', { title: 'Raging Flame Laboratory - Contact', msg: 'Message sent! Thank you.', err: false, page: 'contact' })
- //console.log("success");
- }
- });
- });
- app.listen(8081, function() {
- console.log('Server running at http://127.0.0.1:8081/');
- });
- <form action="http://127.0.0.1:8087/contact" method="post">
- <b>send us a quote</b></br>
- <input type="text" name="name" id="name" value="Name"></br>
- <!--input type="text" name="bname" id="bname" value="Business Name"></br>-->
- <input type="text" name="email" id="email" value="Email Address"></br>
- <textarea name="message" id="message" cols="30" rows="10">Enter detailed information here</textarea></br>
- <input type="submit" name="Submit" id="Submit" value="send message">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement