-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmailtest.php
More file actions
48 lines (43 loc) · 1.26 KB
/
mailtest.php
File metadata and controls
48 lines (43 loc) · 1.26 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
<!DOCTYPE html>
<html>
<head>
<title>Email Sending Example</title>
</head>
<body>
<button onclick="sendEmail()">Send Email</button>
<script>
function sendEmail() {
const sendGridUrl = 'https://api.sendgrid.com/v3/mail/send';
const apiKey = '9bf0ae94941e353dcb2a9f42065f2590';
const emailData = {
personalizations: [
{
to: [{ email: 'kewaltailor345@gmail.com' }],
subject: 'Test Email'
}
],
from: { email: 'kewaltailor999@gmail.com' },
content: [{ type: 'text/plain', value: 'This is a test email sent using SendGrid API.' }]
};
fetch(sendGridUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + apiKey
},
body: JSON.stringify(emailData)
})
.then(response => {
if (response.ok) {
console.log('Email sent successfully.');
} else {
console.error('Failed to send email.');
}
})
.catch(error => {
console.error('Error occurred:', error);
});
}
</script>
</body>
</html>