DEV Community

How to send emails from a form in React (EmailJS)

Dalibor Belic on March 09, 2021

Intro This post will guide you through the process of creating a form and functionality in ReactJS (with hooks) that will enable us to s...
Collapse
 
boly38 profile image
Brice •

to complete about dep: emailjs free plan it's 200 emails per month
there is also sendgrid service (100 mail per day) sendgrid.com/pricing/
there is maybe (ton of) other free providers. Thanks for this post 👏

Collapse
 
daliboru profile image
Dalibor Belic •

Thanks for sharing, and you're welcome!

Collapse
 
julienp17 profile image
Julien Pause •

You have a small typo in the second code preview of the React part.
It should be </button> instead of <button/> (the slash is misplaced).
Great article though! It helped me for the contact page of my (future) website. 😉
EmailJS also offer their own implementation for React.

Collapse
 
amrindra profile image
Amrindra •

Hi there, do you happen to know if it works with .env? I tried to put my userID and serviceID in the .env file, but for some reasons it doesn't work. That's why I am wondering if emailjs work with .env file. Thank you.

Collapse
 
dreamchaser profile image
gard •

Hi i had the same issue when trying to access the variable names in my .env file. I found a solution from the following link .

Collapse
 
vladav profile image
vladaV •

Hi, did you find solution for .env and EmailJS? I have a same problem, and didn't find any workable solution.

Collapse
 
nodedev profile image
Angel Rodriguez •

For those having issues setting up your .env, here's a good article (only if you've used Vite to set up your React app, not sure about CRA).

Mastering Environment Variables in Vite

Collapse
 
lucasfrutig0 profile image
lucasfrutig0 •

Niiiice

Collapse
 
daliboru profile image
Dalibor Belic •

Tnx!

Collapse
 
huydzzz profile image
Pơ Híp •

you are kind

Collapse
 
huydzzz profile image
Pơ Híp •

this mean a lot to me

Collapse
 
toluc profile image
Toluwanimi Adeyemo •

Thanks for the tutorial, it's helpful.
Pls, how do I go about sending file attachments with emailjs and react.

Collapse
 
sylwiavargas profile image
Sylwia Vargas •

That’s fantastic! I’ll share your blog post with my students ✨

Collapse
 
daliboru profile image
Dalibor Belic •

Awesome! This means a lot! :)

Collapse
 
officialrj18 profile image
Rajendra Arya •

Thanks man, it was really helpful,
we can also do this from formsubmit, its also a great and easy tool for form submission.

Collapse
 
akwasin profile image
akwasin •

Worked like a charm. Thanks for this post.

Collapse
 
hrqmonteiro profile image
Henrique Monteiro •

Yeah, literally doesn't fucking work. I press the Submit button and nothing happens.

Collapse
 
hardikchopra profile image
Hardik Chopra •

Thanks for the tutorial 👍
Working fine for me. Btw, is there any other email service better than emailJS?

Collapse
 
timjini profile image
Timjini •

amazing, I will just mention again the typo :)))