Skip to content

Commit a268db2

Browse files
committed
change sendgrid email
1 parent c2174a8 commit a268db2

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

pages/api/contact.js

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,34 @@ export default async (req, res) => {
1010
}
1111

1212
try {
13-
const { name, email: emailAddress, subject, message, subscribe, gReCaptchaToken } = req.body;
13+
const {
14+
name,
15+
email: emailAddress,
16+
subject,
17+
message,
18+
subscribe,
19+
gReCaptchaToken,
20+
} = req.body;
1421

1522
// verify recaptcha token
16-
const reCaptchaValidation = await (await fetch('https://www.google.com/recaptcha/api/siteverify', {
17-
method: 'POST',
18-
headers: {
19-
'Content-Type': 'application/x-www-form-urlencoded'
20-
},
21-
body: `secret=${process.env.RECAPTCHA_SECRET_KEY}&response=${req.body.gReCaptchaToken}`
22-
})).json();
23+
const reCaptchaValidation = await (
24+
await fetch('https://www.google.com/recaptcha/api/siteverify', {
25+
method: 'POST',
26+
headers: {
27+
'Content-Type': 'application/x-www-form-urlencoded',
28+
},
29+
body: `secret=${process.env.RECAPTCHA_SECRET_KEY}&response=${req.body.gReCaptchaToken}`,
30+
})
31+
).json();
2332

2433
if (reCaptchaValidation.success) {
25-
// TODO: change the emails to '[email protected]' before PR
34+
// TODO: change the emails to '[email protected]' before PR
2635
// receiverEmail: The email will be sent here
27-
const receiverEmail = process.env.SENDGRID_DEV_EMAIL;
36+
const receiverEmail = '[email protected]';
2837
// sendgridEmail: This is the email verfied by sendgrid
2938
// the email will appear to be sent from this email
3039
// If a non verified email is used, we get a 403 error
31-
const sendgridEmail = process.env.SENDGRID_DEV_EMAIL;
40+
const sendgridEmail = '[email protected]';
3241

3342
const emailContent = `
3443
<b>Name:</b> ${name} <br/>
@@ -42,33 +51,32 @@ export default async (req, res) => {
4251
to: receiverEmail,
4352
from: {
4453
email: sendgridEmail,
45-
name: 'Web Dev Path'
54+
name: 'Web Dev Path',
4655
},
4756
replyTo: {
4857
email: emailAddress,
49-
name
58+
name,
5059
},
5160
subject: `New message from ${name} via webdevpath.co 'Contact Us' Form`,
5261
content: [
5362
{
54-
'type': 'text/html',
55-
'value': emailContent
56-
}
57-
]
63+
type: 'text/html',
64+
value: emailContent,
65+
},
66+
],
5867
};
5968
await sendgrid.send(email);
6069
res.status(200).json({ status: 'OK' });
61-
}else{
70+
} else {
6271
return res.status(422).json({
63-
status:'error',
64-
message: 'Invalid ReCaptcha'
65-
})
72+
status: 'error',
73+
message: 'Invalid ReCaptcha',
74+
});
6675
}
6776
} catch (e) {
6877
return res.status(500).json({
6978
status: 'error',
70-
message: `Error: ${e.message}`
79+
message: `Error: ${e.message}`,
7180
});
7281
}
73-
74-
}
82+
};

0 commit comments

Comments
 (0)