-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact-script.js
56 lines (45 loc) · 1.52 KB
/
contact-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const form = document.getElementById("form");
var firstName = form.elements["first"].value;
var lastName = form.elements["second"].value;
var email = form.elements["email"].value;
var telly = form.elements["telly"].value;
var subject = form.elements["subject"].value;
var message = form.elements["message-box"].value;
const submit = getElementById("Submit");
// const returnHome = getElementById("Return");
function Submit() {
// enter form data //
// submit form //
}
const nodemailer = require('nodemailer');
const mailgun = require('nodemailer-mailgun-transport');
const transporter = nodemailer.createTransport(mailgun({
auth: {
api_key: process.env.API_KEY,
domain: process.env.DOMAIN,
}
}));
const mailOptions = {
from: [email], //user's mail address, you can make it dynamic from contact form
to: "mertus.malik@gmail.com", //the mail address you authorized in mailgun (receipient mail address)
subject: "", //maybe from contact for
text: [form], //maybe from contact for
};
// verifies smtp connection, server is able to accept messages
transporter.verify(function(error,success){
if(error){
console.log(error);
}
else{
console.log("server is good to go");
}
});
// sends message, alerts of success
transporter.sendMail(mailOptions, (error, response) => {
if (error) {
console.log(error);
} else {
console.log("Message Sent!");
alert("Message sent succesfully.")
}
});