Guest User

Untitled

a guest
Nov 11th, 2017
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. var express = require('express');
  2. var bodyParser = require('body-parser');
  3. var app = express();
  4. var path = require('path');
  5. var nodemailer = require('nodemailer');
  6. var xoauth2 = require('xoauth2');
  7. var engine = require('consolidate');
  8.  
  9. // Define the port to run on
  10. app.set('port', (process.env.PORT || 5000));
  11.  
  12.  
  13. // Set static directory before defining routes
  14. app.use(express.static(path.join(__dirname, '/public')));
  15.  
  16. /*
  17. app.set('views', __dirname + '/views');
  18. app.engine('html', engine.mustache);
  19. app.set('view engine', 'html');
  20. */
  21.  
  22.  
  23. app.use('/node_modules', express.static(__dirname + '/node_modules'));
  24. app.use('/fonts', express.static(__dirname + '/fonts'));
  25. app.use(bodyParser.urlencoded({ extended: false }));
  26.  
  27.  
  28. app.get('/', function(req, res) {
  29. res.sendfile('public/index.html');
  30. });
  31.  
  32. app.get('/bodyPaTest', function (req, res) {
  33. console.log(req.body);
  34. res.end(req.body)
  35. });
  36.  
  37. var smtpTrans = nodemailer.createTransport({
  38. service: 'Gmail',
  39. auth: {
  40. user: 'stephenjovon@gmail.com',
  41. pass: 'Bulldogz1'
  42. }
  43. });
  44.  
  45. app.post('/', function (req, res) {
  46. var mailOpts;
  47.  
  48. //Setup Nodemailer transport, I chose gmail. Create an application-specific password to avoid problems.
  49.  
  50. //Mail options
  51. mailOpts = {
  52. from: req.body.name + ' <' + req.body.email+ '>', //grab form data from the request body object
  53. to: 'stephenjovon@gmail.com',
  54. subject: 'Website contact form',
  55. text: req.body.message
  56. }
  57. /* smtpTrans.sendMail(mailOpts, function (error, response) {
  58. //Email not sent
  59. if (error) {
  60. console.log('Error.');
  61. res.render('contact', { title: 'Raging Flame Laboratory - Contact', msg: 'Error occured, message not sent.', err: true, page: 'contact' })
  62. }
  63. //Yay!! Email sent
  64. else {
  65. console.log('Message Sent.')
  66. console.log(req.body.Name + req.body.Email)
  67. res.render('contact', { title: 'Raging Flame Laboratory - Contact', msg: 'Message sent! Thank you.', err: false, page: 'contact' })
  68. }
  69.  
  70. });
  71.  
  72. */
  73. console.log(req.body);
  74. res.json({here: 'we go'})
  75. });
  76.  
  77. // Listen for requests
  78. var server = app.listen(app.get('port'), function() {
  79. var port = server.address().port;
  80. console.log('Magic happens on port ' + port);
  81. });
  82.  
  83. <p>Contact us for more information regarding a specific project.</p>
  84. <form id="contactForm" action="/" name="contactus" method="post" enctype="text/plain" >
  85. <label>Name:</label>
  86. <input type="text" placeholder="Name" name="name" id="name">
  87. <br>
  88. <label>Phone:</label>
  89. <input type="text" placeholder="Phone" name="phone" id="phone">
  90. <br>
  91. <label>Email:</label>
  92. <input type="text" placeholder="Email" name="Email" id="email">
  93. <br>
  94. <label>Message:</label>
  95. <textarea type="text" placeholder="Write Message Here." name="Message" id="message"></textarea>
  96.  
  97. <input type="submit" value="submit" id="send_email">
  98. </form>
Add Comment
Please, Sign In to add comment