-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
57 lines (49 loc) · 1.91 KB
/
Copy pathtest.html
File metadata and controls
57 lines (49 loc) · 1.91 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
<!DOCTYPE html>
<html>
<head>
<title>Send Email</title>
</head>
<body>
<button id="sendEmailButton">Gửi</button>
<script>
// Hàm gọi API gửi email
// Hàm gọi API gửi email (không dùng await)
function sendEmail() {
// Dữ liệu bạn muốn gửi lên server
const emailData = {
email: "supermoffcial@gmail.com", // Địa chỉ email người nhận
subject: "Test Email", // Tiêu đề email
content: "Đây là nội dung email được gửi từ client." // Nội dung email
};
// Gửi yêu cầu POST đến API
fetch("http://localhost:3000/email/send", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(emailData), // Convert object thành JSON
})
.then(response => {
// Xử lý phản hồi từ server
return response.json().then(result => {
if (response.ok) {
alert("Email đã được gửi thành công!");
} else {
console.error("Error:", result.errors);
alert("Có lỗi xảy ra khi gửi email: " + result.errors);
}
});
})
.catch(error => {
// Xử lý lỗi khi fetch thất bại
console.error("Fetch Error:", error);
alert("Có lỗi xảy ra khi kết nối tới server!");
});
}
// Gắn sự kiện vào nút gửi email
document.getElementById("sendEmailButton").addEventListener("click", () => {
sendEmail()
});
</script>
</body>
</html>