简体   繁体   中英

Sending email from static html page

I have been researching for that problem for many hours, and didn't find anything.

So, I have a static html page and button inside it, like that:

<body>
<button id="0">SEND EMAIL TO my@email.com</button>
</body>

And if I press this button, message "Hello" will be sent to my@email.com from my2@email.com

Is it possible to do that thing using only html or javascript or jquery (because i know only that languages)?

There are three ways to do it

Harder Way

You have to implement server code to send a mail

Less Harder Way

You have to use mailgun or sendgrid rest api to send a mail using javascript.

Simpler Way

You have to use https://formspree.io/ to send a mail from your HTML .

Update: Recently I found a way to send email using Google script. You don't need the backend. Explained here https://github.com/dwyl/html-form-send-email-via-google-script-without-server

You can use :

<body>
<a href = 'mailto:my@email?body="Yourbody"&subject="a subject".com'>SEND EMAIL TO my@email.com</a>
</body>

It will open a mail manager (outlook, gmail, ...) to send a new mail. You can describe the body and the subject inside the link

Otherwise you can send data to PHP with a form tag and send an email this PHP.

I'm using https://elasticemail.com/ . Setup is pretty simple, create an account and verify via sms to allow send 150k emails per month for free.

An example of API: https://api.elasticemail.com/v2/email/send?apikey=YourApiKey&subject=YourSubject&from=From@email.com&to=To@email.com&bodyHtml="some html "

Documentation on how to send emails https://api.elasticemail.com/public/help#Email_Send .

I'm not sure but found that "from" and "to" parameters should be real email addresses.

Directly sending mail from static web page is not possible. You can use thirdparty service, i am using service from formspree and it is working fine for me. All you have to do is create your account in fomrspree, verify gmail address and use below snippet in your html page.

<form action="http://formspree.io/your@email.com" method="POST">
  <input type="email" name="_replyto">
    <textarea   name="body">
    </textarea>
  <input type="submit" value="Send">
</form>

formspree is self explainatory.

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