Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default () => (
- <div className="contact">
- <div className="contact__form">
- <form method="post" action="/contact">
- <input name="firstName" field="firstName" placeholder='Name' />
- <input name="e-mail" field="e-mail" placeholder='E-mail' />
- <input name="subject" field="subject" placeholder='Subject' />
- <input name="message" field="message" placeholder='Message' />
- <button type="submit">Submit</button>
- </form>
- </div>
- </div>
- );
- const path = require('path');
- const express = require('express');
- const publicPath = path.join(__dirname, '../public');
- const port = process.env.PORT || 3000;
- const sgMail = require('@sendgrid/mail');
- sgMail.setApiKey(process.env.SENDGRID_API_KEY);
- const app = express();
- app.use(express.static(publicPath));
- app.post('/contact', (req, res) => {
- const msg = {
- to: 'name.surname@gmail.com',
- from: 'name@inbox.lv',
- subject: 'Hello world',
- text: 'Hello plain world!',
- html: '<p>Hello HTML world!</p>',
- };
- sgMail
- .send(msg)
- .then(() => console.log('Mail sent successfully'))
- .catch(error => console.error(error.toString()))
- });
- app.get('*', (req, res) => {
- res.sendFile(path.join(publicPath, 'index.html'));
- });
- app.listen(port, () => {
- console.log('Server is up');
- });
Add Comment
Please, Sign In to add comment