const express = require("express");
const nodemailer = require("nodemailer");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.json());
// POST endpoint to handle form submission
app.post("/send-email", async (req, res) => {
const {
customer,
order_date,
due_date,
phone,
email,
po_number,
job_name,
item_1,
color_1,
size_1,
quantity_1,
subtotal,
tax,
total,
deposit,
balance_due,
} = req.body;
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "[email protected]", // Replace with your email
pass: "your-email-password", // Replace with your email password
},
});
const mailOptions = {
from: "[email protected]",
to: "[email protected]",
subject: "New Order Submission",
text: `
Customer: ${customer}
Order Date: ${order_date}
Due Date: ${due_date}
Phone: ${phone}
Email: ${email}
P.O. Number: ${po_number}
Job Name: ${job_name}
Item Details: ${item_1}, Color: ${color_1}, Size: ${size_1}, Quantity: ${quantity_1}
Subtotal: ${subtotal}, Tax: ${tax}, Total: ${total}, Deposit: ${deposit}, Balance Due: ${balance_due}
`,
};
try {
await transporter.sendMail(mailOptions);
res.status(200).send("Email sent successfully");
} catch (error) {
console.error("Error sending email:", error);
res.status(500).send("Error sending email");
}
});
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});