This project is a contact form built with Next.js, TypeScript, and various tools for form validation, backend email handling, and rate limiting. The goal is to create a functional and secure contact form that can be used in a portfolio or website.
- Frontend: Built with Next.js (TypeScript) using React Hook Form and Yup for form validation.
- Backend: Uses Nodemailer for email functionality and rate limit validation to prevent spam.
- Validation: Form data is validated with Zod and Yup to ensure the inputs are correct before submission.
- Next.js: For server-side rendering and building the application.
- TypeScript: For static typing in JavaScript.
- Nodemailer: For sending emails from the server.
- Zod: For schema validation on the backend.
- React Hook Form: For managing form state and handling validations on the frontend.
- Yup: For form validation on the frontend.
- Rate-Limit Validator: To implement rate limiting to avoid spam submissions.
Before you begin, ensure you have the following installed:
-
Clone the repository:
git clone https://github.com/DharshanSR/contact-form-nextjs-ts.git cd contact-form-nextjs-ts
-
Install dependencies:
npm install
-
Set up environment variables:
Create a
.env.local
file in the root of the project and add the following configurations:[email protected] GMAIL_PASS=app-password RECIPIENT_EMAIL=your-email.com
GMAIL_USER
: Your Gmail address.GMAIL_PASS
: An app-specific password generated in your Google account. (Ensure two-factor authentication is enabled on your account.)RECIPIENT_EMAIL
: The email address where you want to receive the form submissions.
To start the development server, run:
npm run dev
This will run the app on http://localhost:3000
.
- Go to the Contact Me section of the application.
- Fill out the form with your name, email, and message.
- Upon form submission, the data will be validated and an email will be sent to the recipient configured in the
.env.local
file.
.
├── public # Static files like images
├── pages # Next.js pages, includes the form page and API route for handling form submissions
├── components # Reusable components like the form
├── utils # Helper functions for validation and rate limiting
├── styles # Custom CSS and styles
└── README.md # Project documentation
Ensure you have the following variables set in your .env.local
file:
[email protected]
GMAIL_PASS=app-password
RECIPIENT_EMAIL=your-email.com
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.