So I'm trying to add a contact form and I have no idea how to connect it
Fantastic news! We've Found the answer you've been seeking!
Question:
So I'm trying to add a contact form and I have no idea how to connect it so it sends an email. how do i find password-id and email-id? Im using outlook. here's the js code:
const express = require('express'); const path = require('path'); const nodemailer = require('nodemailer'); const dotenv = require('dotenv'); dotenv.config(); let initialPath = path.join(__dirname, "public"); let app = express(); app.use(express.static(initialPath)); app.use(express.json()); app.get('/', (req, res) => { res.sendFile(path.join(initialPath, "index.html")); }) app.post('/mail', (req, res) => { const { firstname, lastname, email, msg } = req.body; const transporter = nodemailer.createTransport({ service: 'gmail', auth: { user: process.env.EMAIL, pass: process.env.PASSWORD } }) const mailOptions = { from: 'sender id', to: 'reciever id', subject: 'Commission', text: `First name: ${firstname}, Last name: ${lastname}, Email: ${email}, Message: ${msg}` } transporter.sendMail(mailOptions, (err, result) => { if (err){ console.log(err); res.json('opps! it seems like some error occured plz. try again.') } else{ res.json('thanks for e-mailing me. I will reply to you within 2 working days'); } }) }) app.listen(3000, () => { console.log('listening.....'); })
Related Book For
Introduction To Materials Management
ISBN: 978-9386873248
8th edition
Authors: Arnold J. R. Tony, Gatewood Ann K., M. Clive Lloyd N. Chapman Stephen
Posted Date: