2

I have created one html static inquiry form and i want to write a code on submit action in which when we click on submit, One email will send on my account.

How can i write a code in static html form to send email in static html page?

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Atul Patel
  • 163
  • 2
  • 4
  • 9

4 Answers4

3

Only HTTP(S) URIs are safe for use in form actions. You need a server side process to send email (even if it is an externally hosted, third party service). Attempts to do this purely client side are too unreliable to use.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

Check out the answer posted here https://stackoverflow.com/a/34653647/1609406

tl;dr

<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>
Community
  • 1
  • 1
0

Unfortunately you cant automatically send a email from a html/static file, you would have to use some server technology to process the request and send the email.

its not to difficult to do though, so check out this tutorial from css tricks css tricks email in php tutorial

there is also the php docs here php.net docs for mail()

((The above is for PHP, see asp.net email if you are using asp.net (there is also node, java, python etc, but php and c#.net are all I have experience in)

There is always the option to use mailto

<a href='mailto:myemail@me.com'>send an email</a> // etc

However this will only open up the users email client, so could put some users off (as well as making it unusable for people without an email client (although it can be used to open up web based clients such as gmail)) so not ideal.

atmd
  • 7,430
  • 2
  • 33
  • 64
  • because this does not send an email, but opens the email client. – robasta Nov 21 '12 at 11:48
  • True, which Is why I asked if he was 'better of' (or better off due to a spelling mistake) using a mailto, as the question said it was from a static html file (i.e. no server code) and I did put "IF" serverside code isnt an option in my answer – atmd Nov 22 '12 at 14:42
  • Hi atmd, I think the downvote is because it sounds like you're suggesting the developer can cause mail to be sent automatically simply by using the "mailto:" link. This is not true, as a mailto link simply opens the default email client, requiring the user to manually fill out and manually send the email. You could fix your answer to clarify what you mean, which may avoid more downvotes or even reverse them. The best answers on Stack Overflow contain plenty of detail and explanation so that people don't misunderstand. Good luck! – jamesmortensen Nov 23 '12 at 07:46
  • 2
    @atmd As an alternate option `mailto` is not bad but please add relevant details about using it, such as pros and cons. So that the OP can evaluate which option is better for the problem. – Aziz Shaikh Nov 23 '12 at 07:47
  • @AzizShaikh & jmort253, yeah you both makes sense, will give more details in my answer in future. Cheers – atmd Nov 23 '12 at 10:40
  • 1
    @atmd Sounds great. How about starting with this answer and add details. Its never too late on Stack Overflow :) Best Regards – Aziz Shaikh Nov 23 '12 at 10:44
  • thanks. will update my answer now, didnt know you could comeback and update it so long after it was given – atmd Nov 23 '12 at 15:30
0

You can't do this with pure static HTML. You'll need to use some sort of server side scripting, via an embedded language like PHP/Python/Perl/Ruby/etc., or a CGI handoff to a custom executable.

Alex Howansky
  • 50,515
  • 8
  • 78
  • 98