Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

javascript - 如何从JavaScript发送电子邮件(How to send an email from JavaScript)

I want my website to have the ability to send an email without refreshing the page.(我希望我的网站能够发送电子邮件而不刷新页面。)

So I want to use Javascript.(所以我想使用Javascript。) <form action="javascript:sendMail();" name="pmForm" id="pmForm" method="post"> Enter Friend's Email: <input name="pmSubject" id="pmSubject" type="text" maxlength="64" style="width:98%;" /> <input name="pmSubmit" type="submit" value="Invite" /> Here is how I want to call the function, but I'm not sure what to put into the javascript function.(这是我要调用的函数的方式,但是我不确定要在javascript函数中放入什么。) From the research I've done I found an example that uses the mailto method, but my understanding is that doesn't actually send directly from the site.(通过研究,我发现了一个使用mailto方法的示例,但我的理解是实际上并没有直接从站点发送邮件。) So my question is where can I find what to put inside the JavaScript function to send an email directly from the website.(所以我的问题是,在哪里可以找到要放在JavaScript函数中的内容,以便直接从网站发送电子邮件。) function sendMail() { /* ...code here... */ }   ask by user906357 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can't send an email directly with javascript.(您不能直接使用javascript发送电子邮件。)

You can, however, open the user's mail client:(但是,您可以打开用户的邮件客户端:) window.open('mailto:[email protected]'); There are also some parameters to pre-fill the subject and the body:(还有一些参数可以预填充主题和身体:) window.open('mailto:[email protected]?subject=subject&body=body'); Another solution would be to do an ajax call to your server, so that the server sends the email.(另一个解决方案是对服务器进行ajax调用,以便服务器发送电子邮件。) Be careful not to allow anyone to send any email through your server.(注意不要让任何人通过您的服务器发送任何电子邮件。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...