简体   繁体   中英

How To send an Email from a client side angular form without server side application for Contact us form

I have an angular website (pwa website) without server side ( no database ) and I have a contact us form that I want to allow end user to send some data like "name","email","topic" and ... to a specific email like "info@gtx.com"

Currently I uploaded the website without contact us form on a Host domain.

I'm using angular 7 for the website

I am currently this service called FormSpree , which allows us to handle email contact forms without the need for server-side code. It has been working decently well, even up till now.

1) You can handle it purely on your component.html, after specifying the name attribute and adding the POST request url on your form's action attribute.

<form action="https://formspree.io/your@email.com" method="POST" />
.
.
<input type="text" name="name">

2) Or, you can handle it on your component.ts/service.ts by calling HttpClient to send a post request to ' https://formspree.io/your@email.com ', together with the request body and headers.


Alternatively, you may want to use SendGrid, though I may not be of much help here, since I have not actually tried it. However, they seem to have a pretty extensive API and decent documentation , so you may want to refer to that on how to get started with it.

You can not send email directly through front end code. Instead you can

  • use end users mail client.
  • use a thrid party web service.
  • use your own back end service.

(You can put the back end code in the same application and host it as one application. https://nodemailer.com/about/ is a lib for sending mail using back end js code)

What i did was used an email api (mailthis.to) with a postmessage inside the service to send an email. and it works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM