Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

form-to-mail

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

form-to-mail

A Simple Form Mailer. ✉

  • 1.0.0
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Form To Mail

Form To mail is a simple way to receive emails ✉ from contact forms on your website. Which handles files uploads on the fly for you Out of the box itself. Just Plugin the formToMail middleware and setup the .env variable's. You are good to go.

In development test SMTP service account from ethereal.email are generated and Preview URL's are logged. you can visit them to view the emails.

Getting Started

1. Install

npm install form-to-mail

2. Setup SMTP and Mail Options

Create a .env file in the root of your project with below environmental variables and fill them with your credentials.

# SMTP
SMTP_HOST=
SMTP_PORT=
SMTP_USER=
SMTP_PASSWORD=

#Mail Options
MAIL_FROM_NAME=
MAIL_FROM_EMAIL=
MAIL_TO_NAME=
MAIL_TO_EMAIL=

Example

Suppose you have this HTML from in your contact page.Set the form action URL to your Custom endpoint.

contact-form.html

<form action="/" method="POST">

    <div>
        <label for="name" class="form-label"> Full Name </label>
        <input type="text" name="name" id="name" placeholder="Full Name" class="form-input" />
    </div>

    <div>
        <label for="email" class="form-label"> Email Address </label>
        <input type="email" name="email" id="email" placeholder="Enter your email" class="form-input"/>
    </div>

    <div>
        <label for="subject" class="form-label"> Subject </label>
        <input type="text" name="subject" id="subject" placeholder="Enter your subject" class="form-input"/>
    </div>

    <div class="mb-5">
        <label for="message" class="form-label"> Message </label>
        <textarea rows="6" name="message" id="message" placeholder="Type your message" class="form-input"></textarea>
    </div>

    <div>
        <button class="form-btn">Submit</button>
    </div>

</form>

3. Create a express app

creates the routes for the POST endpoint. and add formToEmail middleware which will handle the form submission for you. After that you can redirect the users to a confirmation / thank you page or you cloud send a custom response.

const express = require('express')
const app = express()
const port = 3000
const formToMail = require('form-to-mail')


app.get('/', (req, res) => res.sendFile('contact-form.html'))
app.get('/thank-you', (req, res) => res.sendFile('thank-you.html'))

// POST endpoint
app.post('/',formToMail, (req, res) => {
    res.redirect(303, '/thank-you');
})

app.listen(port, () => console.log(`listening on port ${port}!`))

Sample Form Submission

Sample Form Submission

You can find the sample Contact and Thank you pages inside the test folder.

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Keywords

FAQs

Package last updated on 24 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc