0

Contact Form API

This is an API based on FastAPI designed to send contact forms via SMTP and Discord Webhooks, then receive notifications through Email and Discord, while also storing the information in PostgreSQL.

Contact Form API

Welcome to Contact Form API documentation. This is FastAPI-based API is designed for submitting contact forms and receiving notifications. Follow the instructions below to install and use the API.

Table of Contents

Features

  • Submit contact forms with the following fields:
  • Name
  • Email
  • Phone
  • Title
  • Message
  • Send email notifications to the recipient using an SMTP server
  • Send Discord notifications to a Discord webhook
  • Store contact form submissions in a PostgreSQL database
  • API documentation using Swagger UI and ReDoc

Requirements

  • Python 3.8+

The API is built using the following libraries:

Installation

Running Locally

To run the API locally, follow these steps:

Note:

  • Make sure you have Python 3.8+ installed on your system.
  • You need to have a PostgreSQL database running on your system and create a database for the API. Refer to the PostgreSQL documentation for more information.

  • Clone the repository:

git clone https://github.com/nguyenhongthe/contact_form_api.git
cd contact_form_api
  1. Install the required dependencies:
pip install -r requirements.txt
  1. Create a .env file in the root directory and set the necessary environment variables. Refer to the .env.example file for guidance.

  2. Run the API server:

uvicorn main:app --host 0.0.0.0 --port 8000 --reload

The API should now be up and running at http://localhost:8000.

Usage

API documentation can be accessed through the following URLs:

Submitting a Contact Form

To submit a contact form, send a POST request to the /submit-contact-form endpoint with the following form parameters:

  • name: Name of the sender
  • email: Email of the sender
  • phone: Phone number of the sender
  • title: Title of the message
  • message: Message content

Example using cURL:

curl -X 'POST' \
  'http://localhost:8000/submit-contact-form' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'name=My%20Name&email=myname%40gmail.com&phone=0123456789&title=Hello&message=Hello%20World'

Configuration

The application uses environment variables for configuration. Make sure to define these variables in the .env file before running the application. Refer to the .env.example file for a list of required variables.

For detailed configuration options, consult the Settings class in the main.py file.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request if you find a bug or want to improve the API.

License

This project is licensed under the MIT License. See LICENSE for more information.