1

I have a form which includes the input field and submit button.

<form class="subscribe">
      <div class="">
        <input type="text" placeholder="Your e-mail adresss">
        <span>
          <button type="button">Subscribe</button>
        </span>
      </div>
    </form>

What is the easiest way to make this functional using front-end only so that when new email is entered I will receive an email with the new signup info. Is this possible with JS/Jquery only?

user3187469
  • 1,461
  • 7
  • 23
  • 31
  • nope. not possible. You cannot send emails directly from javascript. You need a mail server to send them – musefan Feb 28 '14 at 12:24
  • You want an email to be sent to you from a client's actual **browser**? If that's what you're after, it's not going to happen, for very good security reasons. You need server side code for that – freefaller Feb 28 '14 at 12:24
  • When user enters email and click on subscribe I just want to receive a notification (email) about this new signup. – user3187469 Feb 28 '14 at 12:25
  • In that case, write server-side code. Javascript will never allow you to send directly from a client's browser. – freefaller Feb 28 '14 at 12:26
  • First of all, OP should learn the basics of HTTP... – ˈvɔlə Mar 03 '14 at 11:10

4 Answers4

2

Yes this is possible now! You dont even need javascript/jquery to implement this.

There is a good API Endpoint that you can use to send an email such as this one: https://formsubmit.co

You can read through the documentation for more information. But here is a little snippet that you can use:


<!--
*Provide your email address on action attribute
*The email you provide on action attribute will be the one to receive an email.
-->
<form action="'https://formsubmit.co/yourEmail@email.com" method="POST">
   <input name="email" type="email" required>
   <!-- You can add more input/fields, this message input is just to notify you about the subscribers-->
   <input hidden name="message" value="Hey! I want to subscribe on your news letter." type="text">
   
   <button type="submit">Subscribe</button>
</form>

Darwin Marcelo
  • 448
  • 5
  • 12
1

That's not possible in the front end. You have to do this server side.

The only thing possible with pure javascript is bringing up the users default email client with a predefined message. But the user will still have to send it.

function sendMail() {
    var link = "mailto:me@example.com"
             + "?cc=myCCaddress@example.com"
             + "&subject=" + escape("This is my subject")
             + "&body=" + escape(document.getElementById('myText').value)
    ;

    window.location.href = link;
}
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
0

If you want to sent any mail you have to use server side function, But javascript/jquery is client side script.

you can do this make a ajax request and send all data then send mail with your need.

Hasibur
  • 205
  • 1
  • 10
0

javascript or jquery cant provide that facility because it will be loaded and executed in client side browser. To send a mail you need protocal(SMTP) and server help. Solution:

1.Use AJAX and serialize your form elements and post it to server file

2.Create your server side file and in that get the posted value and send a mail.ex: php(server side)

 mail("youremailaddress@gmail.com", "subject" .$email, $message);

Need more stuff see this ..

Community
  • 1
  • 1
kamesh
  • 2,374
  • 3
  • 25
  • 33
  • I've tried this solution but couldn't get it to work. I've opened new question to avoid confusion: http://stackoverflow.com/questions/22096313/submiting-form-to-email-address – user3187469 Feb 28 '14 at 13:20