Add contact form validation
This commit is contained in:
parent
2a4cf52465
commit
d3465c6ea3
12 changed files with 429 additions and 204 deletions
43
server/api/contact.post.js
Normal file
43
server/api/contact.post.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
import Mailjet from 'node-mailjet';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
|
||||
// Handle request
|
||||
const body = await readBody(event);
|
||||
|
||||
// Instantiate and setup Mailjet
|
||||
const mailjet = new Mailjet({
|
||||
apiKey: useRuntimeConfig().mailjetApiPublic,
|
||||
apiSecret: useRuntimeConfig().mailjetApiPrivate
|
||||
});
|
||||
|
||||
// Send email
|
||||
try {
|
||||
const response = await mailjet
|
||||
.post('send', { version: 'v3.1' })
|
||||
.request({
|
||||
Messages: [
|
||||
{
|
||||
From: {
|
||||
Email: 'contact@paulnicoue.com',
|
||||
Name: body.name,
|
||||
},
|
||||
To: [
|
||||
{
|
||||
Email: 'contact@paulnicoue.com',
|
||||
Name: 'Paul Nicoué',
|
||||
},
|
||||
],
|
||||
Subject: body.subject,
|
||||
TextPart: body.message
|
||||
}
|
||||
]
|
||||
});
|
||||
console.log(response.body);
|
||||
} catch (error) {
|
||||
console.log(error.statusCode);
|
||||
}
|
||||
|
||||
// End response without providing data
|
||||
event.node.res.end();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue