Repository navigation
Expand file tree
/
Copy pathContact.js
More file actions
70 lines (57 loc) · 1.87 KB
/
Copy pathContact.js
File metadata and controls
70 lines (57 loc) · 1.87 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
#############################
# #
# Javascript for Contact. #
# #
#############################
https://www.emailjs.com/docs/sdk/init/
Note: using emailjs.com to send email. Must use template provided by them, and any variable such as {{name}} in the template must be provided by javascript code.
This is done in the templateParams values.
*/
function get_message() {
let sender_name = document.getElementById("sender_name").value;
let message_body = document.getElementById("message_body").value;
if (`${message_body}` || null){
send_email(message_body, sender_name);
}
else if (`${message_body}` == ""){
alert("Please enter a message.");
}
}
function send_email(message_body, sender_name) {
let service_ID = "service_xgvuuui";
let template_ID = "template_vmxsndu";
console.log("sending message....");
emailjs.init({
publicKey: 'u7ZurD_SGAuxjceJ6',
// Do not allow headless browsers
blockHeadless: true,
blockList: {
// Block the suspended emails
list: ['elliotmollman@yahoo.com', 'emollman27@gmail.com'],
// The variable contains the email address
watchVariable: 'userEmail',
},
limitRate: {
// Set the limit rate for the application
id: 'app',
// Allow 1 request per 10s
throttle: 10000,
},
});
let templateParams = {
name: sender_name,
message: message_body,
};
emailjs.send(service_ID, template_ID, templateParams).then(
(response) => {
console.log('SUCCESS!', response.status, response.text);
alert(`message has been sent ${sender_name}`);
document.getElementById("sender_name").value = '';
document.getElementById("message_body").value = '';
},
(error) => {
console.log('FAILED...', error);
},
);
}