Guest User

Untitled

a guest
Oct 21st, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. <form id='contactForm' class='ajax-form' action="/contactForm" method="POST">
  2. <input type="text" class="name" name="name" placeholder="Your name">
  3. <input type="text" class="email" name="email" placeholder="Your email address">
  4. <textarea name="message" class="message" placeholder="Enter your message">Hello, I am interested in the property for sale on <%= listings.location %>. Can you please contact me with more information?</textarea>
  5. <div class="form-btn">
  6. <input type="submit" class="submit" value="Submit">
  7. </div>
  8. </form>
  9.  
  10. router.post("/contactForm", function(req, res){
  11.  
  12.  
  13. //lookup rentals using ID
  14. Listings.findById(req.params.id, function(err, listings){
  15. if(err){
  16. console.log(err);
  17. res.redirect("/listings");
  18. } else {
  19. console.log('this was the listing we found:' + listings)
  20.  
  21. // ADDING EMAIL FUNCTIONALITY
  22. var nodemailer = require('nodemailer');
  23. var sgTransport = require('nodemailer-sendgrid-transport');
  24.  
  25. var options = {
  26. auth: {
  27. api_user: 'myusername',
  28. api_key: 'mykey'
  29. }
  30. }
  31.  
  32. var client = nodemailer.createTransport(sgTransport(options));
  33.  
  34. var email = {
  35. from: 'RealEstate',
  36. to: 'email',
  37. subject: 'New Contact:',
  38. text: 'Someone just posted a new comment on your listing: Check out the new comment here:'
  39. };
  40.  
  41. client.sendMail(email, function(err, info){
  42. if (err ){
  43. console.log(err);
  44. }
  45. else {
  46. console.log('Message sent: ' + info.response);
  47. }
  48. });
  49. req.flash("success", "Successfully added comment");
  50. res.redirect('/listings/')
  51. }
  52. });
  53. });
Add Comment
Please, Sign In to add comment