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?
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?
Share asked Feb 28, 2014 at 12:20 user3187469user3187469 1,5318 gold badges24 silver badges32 bronze badges 5- nope. not possible. You cannot send emails directly from javascript. You need a mail server to send them – musefan Commented Feb 28, 2014 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 Commented Feb 28, 2014 at 12:24
- When user enters email and click on subscribe I just want to receive a notification (email) about this new signup. – user3187469 Commented Feb 28, 2014 at 12:25
- In that case, write server-side code. Javascript will never allow you to send directly from a client's browser. – freefaller Commented Feb 28, 2014 at 12:26
- First of all, OP should learn the basics of HTTP... – ˈvɔlə Commented Mar 3, 2014 at 11:10
4 Answers
Reset to default 2Yes 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/[email protected]" 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>
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:[email protected]"
+ "[email protected]"
+ "&subject=" + escape("This is my subject")
+ "&body=" + escape(document.getElementById('myText').value)
;
window.location.href = link;
}
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.
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("[email protected]", "subject" .$email, $message);
Need more stuff see this ..