---
title: "Discussion on \"How to Build a Contact Form with JavaScript and NodeMailer\" | Hashnode"
description: "Discussion on \"How to Build a Contact Form with JavaScript and NodeMailer\". Hello everyone! This article is dedicated to Oluwaseun Dabiri, as requested. I'm quite busy this week to write on a short moment's notice but I somehow managed to write and build this mini project. If you are reading this, I hope it helps. I didn't h..."
url: "https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to Build a Contact Form with JavaScript and NodeMailer](https://blog.lo-victoria.com/how-to-build-a-contact-form-with-javascript-and-nodemailer?utm_source=hashnode&utm_medium=feed)

Hello everyone! This article is dedicated to Oluwaseun Dabiri, as requested. I'm quite busy this week to write on a short moment's notice but I somehow managed to write and build this mini project. If you are reading this, I hope it helps. I didn't h...

Aug 19, 2020 · 6 min read · blog.lo-victoria.com  
Updated Nov 11, 2023  
Read the article

-   [#nodejs](https://hashnode.com/tag/nodejs)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#express](https://hashnode.com/tag/express)
-   [#beginners](https://hashnode.com/tag/beginners)
-   [#web-development](https://hashnode.com/tag/web-development)

## Written by

[Victoria Lo](https://hashnode.com/@victoria)

@victoria · Singapore

  
[View profile](https://hashnode.com/@victoria)

A nerd in books, tea, games and software.

I'm a solutions engineer lead, GitHub Star, Director of WomenDevsSG, and co founder of ragTech. I work at the intersection of tech, systems, and leadership, and this blog is where I share my journey through all three. Expect honest reflections, real experiences, and thoughts that are still forming rather than polished career advice.

## Responses 9

Markdown supported · ⌘↵ to post

[Marsh Mallow](https://hashnode.com/@marshmallow608)

[Nov 1, 2023](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/65428b9f9ba50faa87406d31)

Thanks for the blog post, Victoria. I just want to point out that the link to the article in Step 5.2 on port numbers is broken.

[Victoria Lo](https://hashnode.com/@victoria)

[Nov 11, 2023](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/65428b9f9ba50faa87406d31#reply-654f5c510701ac13578c35c0)

Updated! Thanks [Marsh Mallow](https://hashnode.com/@marshmallow608) for kindly letting me know ;)

[Jonathan Obi](https://hashnode.com/@jolomi)

[Apr 24, 2023](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/644707d1a0ebe4540f920095)

Is there a reason using a different action than "send" in the form would not work even if though I change to fetch api to fetch from the new action?

[Jonathan Obi](https://hashnode.com/@jolomi)

[Apr 24, 2023](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/644707d1a0ebe4540f920095#reply-6447080828221b47cc490bb8)

Also thank you so much for this post, it has been very helpful

[Victoria Lo](https://hashnode.com/@victoria)

[Apr 27, 2023](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/644707d1a0ebe4540f920095#reply-644a19c75c7f2d85a97f0c83)

Hi [Jonathan Obi](https://hashnode.com/@jolomi), you have to change both fetch and server-side side if you want to rename the action to something else. It is not mandatory that it is "send"

[Codex Maximus](https://hashnode.com/@CodexMax)

[Jan 2, 2023](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/63b2b467d23d3c5ea6f522b1)

Thank you very much for sharing this!

However, I have a small wonder. The code (completely copied from your example, with the only exception being the credentials) returns **405 Method Not Allowed**. The error is generated by fetch() in index.js, so server.js never runs.

The result is the same regardless of whether Live Server or Parcel server is used. However, by changing to node's server and to transporter.sendMail in the code, testing of the server.js file is succesful.

Have spent a few days on the matter, would be extremely grateful if you could point out the way (hints from articles like https :// blog.airbrake.io/blog/http-errors/405-method-not-allowed and the like do not help).

Thank you!

[Codex Maximus](https://hashnode.com/@CodexMax)

[Jan 3, 2023](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/63b2b467d23d3c5ea6f522b1#reply-63b3ed5392f96075bc858a4d)

Turns out Victoria Lo's code works great. Using node, solely.

I tried the solution here, as my own didn't seem to work. When Victoria's solution didn't work either, I became suspicious. Still I can't yet satisfactory answer my own question. But at least for new/old developers who found their way to javascript bundlers point out that local "help-servers" like Live Server and Parcels own don't always work as expected. Warnings and shown errors, does not necessarily mean that the code is "wrong". The mail-area is also not the only one where middlewares does not behave as expected. The matter is apparently known, and discussed on forums like GitHub.

So a reminder to myself, before spending weeks with endless troubleshooting and youtube videos: test the solution locally with node's own server first (alternatively on a web host). If the code then does not work, and only then, do I actually know that the error lies in the own code. Unfortunately, it is difficult to avoid bundlers such as gulp, parcel or webpack, but I can't trust them to much.

Again, thank you Victoria Lo for sharing your solutions and experiences!

[Austin Stiefel](https://hashnode.com/@AustinStiefel)

[May 30, 2022](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/629456950989e6b52feb25e9)

I seem to be getting this error every time I attempt to submit the form data.

> Uncaught (in promise) SyntaxError: Unexpected token E in JSON at position 0 VM713:1

Any idea what is causing it?

[Winston H. Muijs](https://hashnode.com/@Winstonhenri)

[May 8, 2022](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/62778cc0dc122f5a4f21f851)

Hi Victory, i really enjoy your work, time and energy to make great articles on your blog.

I would buying you a cup of tea but you don't have a paypal option, so that have to wait :). i have a question about the nodemailer with js. If i try the code, the only email adres that works in the browser is the EMAIL that i set in the env. file. How can i make the code work so it accepts other adresses? Have a great day. Winston

ps.

Other email adresses give the following response: **'553 5.7.1 < -------@gmail.com>: Sender address rejected: not owned by user 3@7316314'** in the terminal.

if any one wants to participate and help, so please!

Thanks!

[Victoria Lo](https://hashnode.com/@victoria)

[May 9, 2022](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/62778cc0dc122f5a4f21f851#reply-6278dc5a766c7b81844fa0ed)

Hi [Winston H. Muijs](https://hashnode.com/@Winstonhenri), so the sender email can only be one but the receiver email can be multiple, comma-separated.

Please refer to the Nodemailer documentation [here](https://nodemailer.com/message/). Hope that helps! Cheers!

[Winston H. Muijs](https://hashnode.com/@Winstonhenri)

[May 9, 2022](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/62778cc0dc122f5a4f21f851#reply-6278fe3840d9ad96a278934d)

Hi Victory, i changed sender to from in my code in my mail const - and that did the job. Thanks for the help !! 🫖👍🏻[Victoria Lo](https://hashnode.com/@victoria)

[Igor Ljevak](https://hashnode.com/@mrAzzar)

[Aug 31, 2021](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/612e23121dd572151d81d0b8)

Hey Victoria thank you for your fantastic work im right now studying front end and found your tutorial but i get this error: POST [igorljevak.com/send](https://igorljevak.com/send) 404

the site is published on that domain

i hope you find time and can help me :D

[Victoria Lo](https://hashnode.com/@victoria)

[Sep 1, 2021](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/612e23121dd572151d81d0b8#reply-612edf9f4e9d8114f8ae01b2)

Hi [Igor Ljevak](https://hashnode.com/@mrAzzar), thanks for reading. Yes, I removed the demo site as there were people spamming me emails everyday. I will update the blog to let everyone know the demo site has been removed. Thanks!

[Igor Ljevak](https://hashnode.com/@mrAzzar)

[Sep 1, 2021](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/612e23121dd572151d81d0b8#reply-612f6ea1bb796223ef279b59)

[Victoria Lo](https://hashnode.com/@victoria) i didn't mean that :D I get that error when i follow the tutorial. its something with the part domain.com/send

my site is published on a domain and in the JS i write domain.com/send, but get the "error: POST 404"

[Darys Raso](https://hashnode.com/@Darys)

[Jan 11, 2021](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/5ffbf15aaa5c467fe155a418)

Hello, first of all thanks a lot for sharing this to us!

I am pretty new using servers in js, especially using express, could you help me out managing what to display after the mail has been sent, I would like to keep my form page but only changing the button style instead of going to the blank page with "Email successfully sent to recipient!" but I can't figure out how to, please help me if you have time to

[Victoria Lo](https://hashnode.com/@victoria)

[Jan 11, 2021](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/5ffbf15aaa5c467fe155a418#reply-5ffbf868aa5c467fe155a4e7)

Hi Darys! Thanks for reading!

Instead of:

```
res.status(200).send("Email successfully sent to recipient!")
```

Replace with:

```
res.status(200).json({status: 'success'})
```

And it will not go to a blank page.

[Darys Raso](https://hashnode.com/@Darys)

[Jan 13, 2021](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/5ffbf15aaa5c467fe155a418#reply-5ffe47b1b00f7510ee958944)

Thank you so much ! You actually did save me

[Bolaji Ayodeji](https://hashnode.com/@bolajiayodeji)

[Aug 22, 2020](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/5f41852fd7d20171d0aadf89)

I learnt a lot from this, thanks for sharing!

[Oluwaseun Dabiri](https://hashnode.com/@dabsclement)

[Aug 19, 2020](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/5f3d688d4539de351ee932da)

thank you so much victoria....

[Victoria Lo](https://hashnode.com/@victoria)

[Aug 19, 2020](https://hashnode.com/posts/how-to-build-a-contact-form-with-javascript-and-nodemailer/5f3d05e179fdf532228edc72/comment/5f3d688d4539de351ee932da#reply-5f3d82a14539de351ee9334f)

No problem :)
