-3

I have HTML form with a textbox where user enter his email - let say to register for a newsletter and a button to join.

When clicking the button I'd like to send myself an email with a constant subject like: 'a new user joined your newsletter' and in the body of the email have the text entered by the user.

So with PHP and Javascript code its possible - i'm looking for a pure html code that does the same (in my index.html file)

using <a href: mailto...> or <form action=mailto:... method=post> or <button onclick:mailto...> opens my mail application :(

  1. Is there a way to send that email in the background (without opening the mail application) with the data from textbox in the email body?
  2. if Yes to Q.1 then is there a way to add a fixed subject
Kukula Mula
  • 1,788
  • 4
  • 19
  • 38
  • Possible duplicate of [How to send an email from JavaScript](http://stackoverflow.com/questions/7381150/how-to-send-an-email-from-javascript) – VLAZ Oct 25 '16 at 19:08
  • No, not from the client side. Not unless you write it to happen server-side. – Ding Oct 25 '16 at 19:09
  • 3
    No, you cannot. – j08691 Oct 25 '16 at 19:09
  • Plus, *"(without opening the mail application)"* - what did you mean by that exactly? – Funk Forty Niner Oct 25 '16 at 19:10
  • For sending mail, you must have an SMTP server. Using PHP, you send e-mail. – selami Oct 25 '16 at 19:10
  • @Fred-ii- Probably referring to the fact that most browsers handle a `mailto:` URL by using the OS's default mail program – jmoerdyk Oct 25 '16 at 19:11
  • 1
    @jmoerdyk Sounds kind of sneaky to me, IMHO. – Funk Forty Niner Oct 25 '16 at 19:11
  • 1
    Yes, the covert sending of a mail on behalf of a user without their consent/knowledge would be underhanded – jmoerdyk Oct 25 '16 at 19:14
  • 1
    This *"send that email in the background"* perplexes me and rubs me the wrong way; I have to be honest here. Far as I'm concerned, you can't and for a lot of reasons. I won't go through them all, since this area doesn't allow for that many characters. – Funk Forty Niner Oct 25 '16 at 19:19
  • @KukulaMula, hey, is anything unclear in my answer? – Max Koretskyi Oct 25 '16 at 19:38
  • @Fred-ii- there's nothing fishy that should rub you the wrong way. Most contact forms works that way by using POST and javascript to send an email without opening the mail app (i.e sending an email in the background). Another example for a background email sending is Airbnb and Booking that send emails from server side to host so the client won't be in direct contact with them (in their case is their business model in others cases it can be for privacy reasons). – Kukula Mula Oct 25 '16 at 20:10
  • 1
    @KukulaMula the difference is that all those are sending emails from the _server_ which is, in most cases, a _trusted_ and _expected_ source. And most importantly it is NOT the user. So, while the email may be sent "in the background" the user is not involved and you know who and why is sending that. If somebody came in and started sending emails in your name from your machine without your knowledge that is _quite_ different. – VLAZ Oct 25 '16 at 20:17

2 Answers2

2

No, there is no way you can send email using pure html. Email is sent over SMTP protocol. A browser operates in HTTP protocol. So it's not possible to send email even using pure javascript. Only server can send data using SMTP protocol.

Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
0

No because you can not send an E-Mail without using an SMTP server. This server must be contacted by PHP or another server-side script (server must receive a form request and process it). You can not contact a SMTP server via pure HTML (that would be really insecure btw).

Regarding mailto: This only works if your clients have installed a mail client on their local machine. This mail client must be properly configured in order to - guess what - contact an SMTP server in order to send the mail.

However it is possible passing a subject via mailto: https://css-tricks.com/snippets/html/mailto-links/

Blackbam
  • 17,496
  • 26
  • 97
  • 150
  • *"However it is possible passing a subject via mailto: https://css-tricks.com/snippets/html/mailto-links/"* - They already included that in the question, so I'm sure they already know how. So their *"if Yes to Q.1 then is there a way to add a fixed subject"* won't apply here, since Q1 is not applicable until they do use the proper method of sending mail. – Funk Forty Niner Oct 25 '16 at 19:18
  • True however just for completeness I wanted to give a hint on how to pass a subject via mailto it will not do any damage :-) – Blackbam Oct 25 '16 at 19:19
  • True, it won't. However the question is by far way too broad and way too unclear for me and am sure there are others who feel the same way. – Funk Forty Niner Oct 25 '16 at 19:20
  • True nvm should be closed maybe. – Blackbam Oct 25 '16 at 19:22
  • TBH, I voted to close as unclear. Comments (and answers) have been given to them, but they've yet to surface, unless they decided to just take off and come back later, who knows ;-) – Funk Forty Niner Oct 25 '16 at 19:23
  • @Fred-ii- I don't think it's _unclear_ as much as "didn't even try googling before posting the question". I only typed in "send email javascript" and found that dupe that already clearly says that you cannot do that and how to actually do it. – VLAZ Oct 25 '16 at 19:26
  • @vlaz Read their question again and read it over very carefully. Read it 10-20 times if needed and you'll see what I mean. Plus, the OP seems to just have "vanished into thin air". I take it they didn't get the "answer" they were looking for. Sending as "pure html"? What does that tell you? They don't want to use PHP and going through the server... that's what I get from it. Let the OP tell me I'm wrong on this one ;-) the question sounds way too fishy for my cup of tea. – Funk Forty Niner Oct 25 '16 at 19:28
  • @Blackbam thanks for your answer, I do know how to send the email with all its data fields using Javascript & Php. I did Google before posting, and still wondered if someone from this community might find a way to do so. One last thing as food for thought to you and Fred -ii: not everyone is a native speaker, although trying my best to explain the problem because of language barriers it might come as unclear, also different people live in different places around the globe, some might be at their work place others cooking dinner or going to bed, so delays in response are expected. – Kukula Mula Oct 25 '16 at 20:29