Possible Duplicate:
how to send email by using javascript or jquery
How can I send an email with JavaScript, that is able to be read by Gmail, Yahoo, etc.?
This is what I have:
<script language="javascript">
function SendEmail()
{
var body = escape(document.Form.textfieldName.value +"\n"+document.Form.textfieldEmail.value +"\n"+document.Form.textfieldMessage.开发者_JAVA百科value);
var sTo="testmail@mail.com";
var subject = "This is SyntaxHelpSub";
window.location.href =
"mailto:"+sTo+"?subject="+subject+"&body="+body;
}
</script>
<div class="formfields">Name: <input class="tbox" id="textfieldName" type="text">
Email: <input class="tbox" id="textfieldEmail" type="text">
<br><br>
Message: <input class="tbox" id="textfieldMessage" type="text" style="width: 343px">
</div>
<br>
<input type="button" value="Send!" onclick="SendEmail()" />
If you really want to send an email via javascript, then you need a cooperating server process that you can make an ajax call to. The javascript ajax call will deliver the contents of the email to the server and the server will send out the actual email.
Browser clients do not actually send emails. The mailto: functionality allows a browser to communicate with the user's chosen email program to ask that program to send out an email on the user's behalf. This functionality may or may not be present or working in any given browser - you have no way of knowing. For example, my wife uses Yahoo mail and mailto: links never work for her because there is no email client program on her computer to coordinate with the browser to send out an email. In my opinion, these days with so many web email clients, it is a bad idea to rely on mailto: functionality in a browser.
If you don't have your own server that can do this for you, then there are some services out there like http://wufoo.com that offer email sending services (some parts of free) and you could likely deliver to them via javascript/ajax. To use Wufoo in this way, you'd have to build a wufoo form the way wufoo expects it to work, include it in your page (it can be hidden), fill it in (it can stay hidden), then submit it via ajax and the wufoo servers would send out the email to your desired destination.
You don't. In pure client side mechanics, you put a link out there with the mailto:
prefix. AKA:
mailto:someaddress@gmail.com?subject=SomeText
Which is what it looks like you are doing, except that the user must click on this; you cannot invoke a send email programmatically. In addition, you also dont have any control over what gmail or yahoo does with email it receives.
精彩评论