npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

usemailprex-react

v1.0.5

Published

Send Emails from your Website with Ease

Downloads

13

Readme

useMailprex

npm version npm downloads

useMailprex is a React hook for handling contact forms and sending data to a server using fetch. This hook simplifies managing the form state and server response.

What is Mailprex?

Mailprex is a service designed to facilitate sending emails from web forms. It handles the backend processes, allowing you to focus on creating and managing your forms without worrying about the complexities of email delivery.

Installation

First, install the package using npm:

npm install usemailprex-react 

Usage

  • Register in https://mailprex.top/, Confirm your account
  • Login in https://mailprex.top/, Get a formToken in dashboard
  • Install the hook in your project and Enjoy

Here is an example of how to use useMailprex in a contact form component in a react.js application.

"use client";
import React from "react";
import { useMailprex } from "usemailprex-react";

const ContactForm = () => {
  const webName = "Mailprex Test";
  const emailDestiny = "[email protected]";
  const url = "https://api.mailprex.top/email/send";
  const formToken = "your-form-token";

  const { formData, handleChange, handleSubmit, response } = useMailprex({
    url,
    webName,
    emailDestiny,
    formToken,
  });
   const handleFormSubmit = async (e) => {
    e.preventDefault();
    await handleSubmit(e);
    if (response.error) {
      alert(
    "Error sending message. Try again later.",
            );
    } else {
       alert( 
        "Message sent succesfully!"
         );
    }
  };

  return (
    <form
      onSubmit={handleFormSubmit}
      className="max-w-lg mx-auto p-4 bg-white shadow-md rounded-lg"
    >
      <div className="mb-4">
        <label
          htmlFor="fullname"
          className="block text-gray-700 font-semibold mb-2"
        >
          Full Name *
        </label>
        <input
          type="text"
          id="fullname"
          name="fullname"
          value={formData.fullname}
          onChange={handleChange}
          className="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"
          placeholder="Full name"
          required
        />
      </div>
      <div className="mb-4">
        <label
          htmlFor="email"
          className="block text-gray-700 font-semibold mb-2"
        >
          Email *
        </label>
        <input
          type="email"
          id="email"
          name="email"
          value={formData.email}
          onChange={handleChange}
          className="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"
          placeholder="Email"
          required
        />
      </div>
      <div className="mb-4">
        <label
          htmlFor="phone"
          className="block text-gray-700 font-semibold mb-2"
        >
          Phone
        </label>
        <input
          type="tel"
          id="phone"
          name="phone"
          value={formData.phone}
          onChange={handleChange}
          className="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"
          placeholder="Phone"
        />
      </div>
      <div className="mb-4">
        <label
          htmlFor="service"
          className="block text-gray-700 font-semibold mb-2"
        >
          Service
        </label>
        <input
          type="text"
          id="service"
          name="service"
          value={formData.service}
          onChange={handleChange}
          className="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"
          placeholder="Service"
        />
      </div>
      <div className="mb-4">
        <label
          htmlFor="message"
          className="block text-gray-700 font-semibold mb-2"
        >
          Message *
        </label>
        <textarea
          id="message"
          name="message"
          value={formData.message}
          onChange={handleChange}
          className="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring focus:border-blue-300"
          rows={4}
          placeholder="Message"
          required
        ></textarea>
      </div>
      <div className="text-center">
        <button
          type="submit"
          className="bg-blue-500 hover:bg-blue-600 text-white font-semibold px-4 py-2 rounded-md transition-colors duration-300"
        >
          Send Message
        </button>
      </div>
      {response.loading && (
        <p className="mt-4 text-blue-500">Sending email...</p>
      )}
      {response.error && (
        <p className="mt-4 text-red-500">
          Error sending email: {response.error.message}
        </p>
      )}
      {response.data && (
        <p className="mt-4 text-green-500">{response.data.message}</p>
      )}
    </form>
  );
};

export default ContactForm;

Example Email

Here is an example of how the emails sent through Mailprex will appear when they arrive at the specified email address:

API

useMailprex

Parameters

  • url: The server URL to send the form data to.
  • webName: The name of the website from which the form is being submitted.
  • emailDestiny: The destination email address.
  • formToken: The form token for authentication.

Returns

  • formData: An object containing the form data.
  • handleChange: A function to handle changes in the form fields.
  • handleSubmit: A function to handle form submission.
  • response: An object containing data, loading, and error regarding the API response.

Contributing

Contributions are welcome. Please open an issue or a pull request for any improvements or fixes.