3

I have to send form datas to an email address. How can I do? I did some research and I understand that you have to use a library to do this. correct? What do you suggest?

1
  • Yeah you have to use a library for that, pick one which suits you the best Commented Apr 16, 2022 at 8:12

4 Answers 4

5

I think this one might be worth looking into - https://www.emailjs.com/docs/sdk/send-form/

Sign up to request clarification or add additional context in comments.

Comments

1

I recommend using EmailJS library. I made an account with the free tier (200 free emails/month) added my gmail account, setup a test template and followed the docs https://www.emailjs.com/docs/examples/reactjs/ and was able to get something working in less than 30 mins.

Comments

0

If you are looking for implementation for Reactjs then use like this :

// install @emailjs/browser
import React, { useRef } from 'react';
import emailjs from '@emailjs/browser';

export const ContactUs = () => {
const form = useRef();

const sendEmail = (e) => {
e.preventDefault();
// service_id, templte_id and public key will get from Emailjs website when you create account and add template service and email service 
emailjs.sendForm('YOUR_SERVICE_ID', 'YOUR_TEMPLATE_ID', form.current, 
'YOUR_PUBLIC_KEY')
  .then((result) => {
      console.log(result.text);
  }, (error) => {
      console.log(error.text);
  });
};

return (
<form ref={form} onSubmit={sendEmail}>
  <label>Name</label>
  <input type="text" name="user_name" />
  <label>Email</label>
  <input type="email" name="user_email" />
  <label>Message</label>
  <textarea name="message" />
  <input type="submit" value="Send" />
</form>
);
};

Comments

0

Just to mention that I also achieved this with the very simple https://formsubmit.co solution.

<form action="https://formsubmit.co/[email protected]" method="POST">
     <input type="text" name="name" required>
     <input type="email" name="email" required>
     <button type="submit">Send</button>
</form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.