Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form id='contactForm' class='ajax-form' action="/contactForm" method="POST">
- <input type="text" class="name" name="name" placeholder="Your name">
- <input type="text" class="email" name="email" placeholder="Your email address">
- <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>
- <div class="form-btn">
- <input type="submit" class="submit" value="Submit">
- </div>
- </form>
- router.post("/contactForm", function(req, res){
- //lookup rentals using ID
- Listings.findById(req.params.id, function(err, listings){
- if(err){
- console.log(err);
- res.redirect("/listings");
- } else {
- console.log('this was the listing we found:' + listings)
- // ADDING EMAIL FUNCTIONALITY
- var nodemailer = require('nodemailer');
- var sgTransport = require('nodemailer-sendgrid-transport');
- var options = {
- auth: {
- api_user: 'myusername',
- api_key: 'mykey'
- }
- }
- var client = nodemailer.createTransport(sgTransport(options));
- var email = {
- from: 'RealEstate',
- to: 'email',
- subject: 'New Contact:',
- text: 'Someone just posted a new comment on your listing: Check out the new comment here:'
- };
- client.sendMail(email, function(err, info){
- if (err ){
- console.log(err);
- }
- else {
- console.log('Message sent: ' + info.response);
- }
- });
- req.flash("success", "Successfully added comment");
- res.redirect('/listings/')
- }
- });
- });
Add Comment
Please, Sign In to add comment