admin管理员组文章数量:1391955
I have a webpage with a text box where the user can enter his email id. I want to send mail to the mail Id Entered.
<form action="mailto:[email protected]" method="post" enctype="text/plain" >
FirstName:<input type="text" name="FirstName">
Email:<input type="text" name="Email">
<input type="submit" name="submit" value="Submit">
</form>
The problem is I want mailto:[email protected]
to be taken from the text box.Then a message should appear saying that email has been sent successfully. Can I do that using javascript?
I have a webpage with a text box where the user can enter his email id. I want to send mail to the mail Id Entered.
<form action="mailto:[email protected]" method="post" enctype="text/plain" >
FirstName:<input type="text" name="FirstName">
Email:<input type="text" name="Email">
<input type="submit" name="submit" value="Submit">
</form>
The problem is I want mailto:[email protected]
to be taken from the text box.Then a message should appear saying that email has been sent successfully. Can I do that using javascript?
-
2
add an id to the email input, say
id="mail"
. thendocument.getElementById("mail").value
. – onemach Commented Mar 3, 2012 at 4:06 - So you want the user send email to himself/herself ?? – xdazz Commented Mar 3, 2012 at 4:09
-
You cannot send mail directly from the client-side. You can set up your form to behave as a
mailto
link, but there is no way to confirm whether or not the message initiated by themailto
was sent successfully. – rjz Commented Mar 3, 2012 at 4:09
2 Answers
Reset to default 3Browser-side JavaScript cannot send email on its own. The best it can do is try to open the user's email application for them so they can send the email. For example:
location.href = 'mailto:' + encodeURIComponent(emailAddress) +
'?subject=' + encodeURIComponent(subject) +
'&body=' + encodeURIComponent(body);
You could hook the submit
event of the form, prevent the default action, and execute that code, and the end result would be they could fill out the form, click submit, their email client opens, and they can click send.
Try it on JSFiddle.
First of all, emails cannot be sent using javascript. It is a client side scripting language only, and cannot send an email without first contacting a server and 'asking' it to send the email using PHP or some other server-side language.
I'm not sure what you mean by saying you want mailto:[email protected]
to be taken from the textbox. mailto:
is just a protocol that causes the browser to open up the user's default email program to send a mail to the given address. You can easily create a mailto: link that the user can click on to do this or pull the email address from an existing mailto: link, but the email still has to be sent some other way.
There are plenty of elaborate ways to tell the user a message has been sent succesfully, but the easiest and most direct is probably a simple alert box:
alert("Your email has been sent succesfully.");
本文标签: htmlHow to send mail using javascriptStack Overflow
版权声明:本文标题:html - How to send mail using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744729937a2621987.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论