如何从提交按钮发送电子邮件? [英] How can I send an e-mail from a submit button?
问题描述
我找不到解决方案。我需要通过电子邮件从提交按钮发送总金额,但它不起作用。有什么想法吗?
------------------------------- -------------------------------------------------- -----
<!DOCTYPE html>
< html>
< head>
< meta charset =utf-8>
< title> SmartHOME< / title>
< style>
body {
background-image:url(watchdogs2.gif);
background-color:#000000;
background-repeat:no-repeat;
background-size:cover;
text-shadow:2px 2px#000000;
颜色:白色;
}
fieldset {
background-color:#3e4f7c;
display:inline-block;
text-shadow:2px 2px#000000;
颜色:白色;
}
h1 {
text-shadow:2px 2px#000000;
颜色:白色;
}
< / style>
<身体克t;
< script type =text / javascript>
函数DisplayPrice(价格){
var val1 = 0;
for(i = 0;我< document.form1.price.length; i ++){
if(document.form1.price [i] .checked == true){
val1 = document.form1.price [i] .value; < br $>
}
}
var val2 = 0;
for(i = 0; i< document.form2.price2.length; i ++){
if(document.form2.price2 [i] .checked == true){
val2 = document.form2.price2 [i] .value;
}
}
var val3 = 0 ;
for(i = 0; i< document.form3.price3.length; i ++){
if(document.form3.price3 [i] .checked = = true){
val3 + = parseInt(document.form3.price3 [i] .value);
}
}
var sum = parseInt(val1)+ parseInt(val2)+ parseInt(val3);
document.getElementById ('totalSum')。value = sum;
}
函数reset(){
for( i = 0;我< document.form1.price.length; i ++)
document.form1.price [i] .checked = false;
for(i = 0; i< document.form2.price2.length; i ++)
document.form2.price2 [i] .checked = false
for(i = 0; i< document.form3.price3.length; i ++)
document.form3.price3 [i] .checked = false < br $>
document.getElementById('totalSum')。value ='';
}
函数SendMail(){
var link =mailto:trendnet.website@gmail.com+
& subject =+ escape(这是主题)+
& body =+ escape(这是身体在这里);
window.location.href = link;
}
函数SendMail(){
var txtTotalAmount = document.getElementById('<%= txtTotalAmount.ClientID %>')。value;
alert(txtTotalAmount);
var link = mailto:trendnet.website@gmail.com+
?cc = abc @ abc.com+
& subject =+ escape(这是主题和总金额是:+ txtTotalAmount+
& body =+ escape(这是正文和总金额是:+ txtTotalAmount);
window.location.href = link;
}
< / script>
< / body>
< body>
< p>< / p>
< i>< h1>< font color =white>& nbsp; SmartHOME< / font>< / h1>< / i>
< p>< / p>
< fieldset>
< legend>< b>< i>第1组:< / i>< / b>< / legend>
< form name =form1id = form1runat =server>
< br>
< input id =rdo_1type =radiovalue =1000name = priceonclick =DisplayPrice(this.value);> Choice 1 - & euro; 1.000,00
< br>
< input id =rdo_2type =radiovalue =2000name =priceonclick =DisplayPrice (this.value);>选择2 - & euro; 2.000,00
< br>
< input id =rdo_3type =radiovalue =5000name =priceonclick =DisplayPrice (this.value);>选择3 - & euro; 5.000,00
< p>< / p>
< / form>
< / fieldset>
< p>< / p>
< fieldset>
< legend>< b>< i>第2组:< / i>< / b>< / legend>
<表格名称=form2id =form2runat =server>
< br>
< input id =rdo_1type =radiovalue =100name =price2onclick =DisplayPrice(this.value);> Choice 1 - & euro; 100,00
< br>
< input id =rdo_2type =radiovalue =200name =price2onclick =DisplayPrice (this.value);>选择2 - & euro; 200,00
< p>< / p>
< / form>
< / fieldset>
< p>< / p>
< fieldset>
< legend>< b>< i>组3:< / i>< / b>< / legend>
< form name =form3id =form3runat =server>
< ; br>
< input id =rdo_1type =checkboxvalue =100name =price3onclick =DisplayPrice(this.value);>选择1 - &安培;欧元; 100,00
< br>
< input id =rdo_2type =checkboxvalue =200name =price3onclick =DisplayPrice (this.value);>选择2 - & euro; 200,00
< br>
< input id =rdo_1type =checkboxvalue =450name =price3onclick =DisplayPrice (this.value);>选择3 - & euro; 450,00
< br>
< input id =rdo_1type =checkboxvalue =600name =price3onclick =DisplayPrice (this.value);>选择4 - & euro; 600,00
< br>
< input id =rdo_1type =checkboxvalue =750name =price3onclick =DisplayPrice (this.value);>选择5 - & euro; 750,00
< p>< / p>
< / form>
< / fieldset>
< p>< / p>
< fieldset>
< legend>< i>< b> TOTAL AMOUNT:< / b>< / i>< / legend>
< table border =0>
< tr>
< td colspan =2align =left>
< form>
& euro; < input type =textname =totalSumid =totalSumvalue =0size =3readonly =readonly>,00
< / td>
< / tr>
< tr>
< td align =left>
< button onclick =reset()>全部清除< / button>
< / form>
< / td>
< / tr>
< / table>
< / fieldset>
< p>< / p> ;
< fieldset>
< legend>< i>< b>提交:< / b>< / i>< / legend>
< table border =0>
< tr>
< td align =left>
< input type =submitname =buttonid =Button1>
< asp:Button ID =Button1runat =serverText =按钮OnClientClick =SendMail()/>
< asp:TextBox ID =txtTotalAmountrunat =serverText =18097 Rs。>
< / td>
< / tr>
< / table>
< / body& gt;
< / html>
我尝试过:
我刚刚尝试更改代码,但它仍然不想工作...
I can't find a solution. I need to send the total amount via e-mail from a submit button but it doesn't work. Any ideas?
--------------------------------------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SmartHOME</title>
<style>
body {
background-image: url("watchdogs2.gif");
background-color: #000000;
background-repeat: no-repeat;
background-size: cover;
text-shadow: 2px 2px #000000;
color: white;
}
fieldset {
background-color: #3e4f7c;
display: inline-block;
text-shadow: 2px 2px #000000;
color: white;
}
h1 {
text-shadow: 2px 2px #000000;
color: white;
}
</style>
<body>
<script type="text/javascript">
function DisplayPrice(price){
var val1 = 0;
for( i = 0; i < document.form1.price.length; i++ ){
if( document.form1.price[i].checked == true ){
val1 = document.form1.price[i].value;
}
}
var val2 = 0;
for( i = 0; i < document.form2.price2.length; i++ ){
if( document.form2.price2[i].checked == true ){
val2 = document.form2.price2[i].value;
}
}
var val3 = 0;
for (i = 0; i < document.form3.price3.length; i++) {
if (document.form3.price3[i].checked == true) {
val3 += parseInt( document.form3.price3[i].value);
}
}
var sum=parseInt(val1) + parseInt(val2) + parseInt(val3);
document.getElementById('totalSum').value=sum;
}
function reset() {
for (i = 0; i < document.form1.price.length; i++)
document.form1.price[i].checked = false;
for (i = 0; i < document.form2.price2.length; i++)
document.form2.price2[i].checked = false
for (i = 0; i < document.form3.price3.length; i++)
document.form3.price3[i].checked = false
document.getElementById('totalSum').value = '';
}
function SendMail() {
var link = "mailto:trendnet.website@gmail.com" +
"&subject=" + escape("This is subject") +
"&body=" + escape("This is body here");
window.location.href = link;
}
function SendMail() {
var txtTotalAmount = document.getElementById('<%= txtTotalAmount.ClientID %>').value;
alert(txtTotalAmount);
var link = "mailto:trendnet.website@gmail.com" +
"?cc=abc@abc.com" +
"&subject=" + escape("This is subject and total amount is: " + txtTotalAmount) +
"&body=" + escape("This is body and total amount is: " + txtTotalAmount);
window.location.href = link;
}
</script>
</body>
<body>
<p></p>
<i><h1><font color="white"> SmartHOME</font></h1></i>
<p></p>
<fieldset>
<legend><b><i>Group 1:</i></b></legend>
<form name="form1" id="form1" runat="server">
<br>
<input id="rdo_1" type="radio" value="1000" name="price" onclick="DisplayPrice(this.value);">Choice 1 - € 1.000,00
<br>
<input id="rdo_2" type="radio" value="2000" name="price" onclick="DisplayPrice(this.value);">Choice 2 - € 2.000,00
<br>
<input id="rdo_3" type="radio" value="5000" name="price" onclick="DisplayPrice(this.value);">Choice 3 - € 5.000,00
<p></p>
</form>
</fieldset>
<p></p>
<fieldset>
<legend><b><i>Group 2:</i></b></legend>
<form name="form2" id="form2" runat="server">
<br>
<input id="rdo_1" type="radio" value="100" name="price2" onclick="DisplayPrice(this.value);">Choice 1 - € 100,00
<br>
<input id="rdo_2" type="radio" value="200" name="price2" onclick="DisplayPrice(this.value);">Choice 2 - € 200,00
<p></p>
</form>
</fieldset>
<p></p>
<fieldset>
<legend><b><i>Group 3:</i></b></legend>
<form name="form3" id="form3" runat="server">
<br>
<input id="rdo_1" type="checkbox" value="100" name="price3" onclick="DisplayPrice(this.value);">Choice 1 - € 100,00
<br>
<input id="rdo_2" type="checkbox" value="200" name="price3" onclick="DisplayPrice(this.value);">Choice 2 - € 200,00
<br>
<input id="rdo_1" type="checkbox" value="450" name="price3" onclick="DisplayPrice(this.value);">Choice 3 - € 450,00
<br>
<input id="rdo_1" type="checkbox" value="600" name="price3" onclick="DisplayPrice(this.value);">Choice 4 - € 600,00
<br>
<input id="rdo_1" type="checkbox" value="750" name="price3" onclick="DisplayPrice(this.value);">Choice 5 - € 750,00
<p></p>
</form>
</fieldset>
<p></p>
<fieldset>
<legend><i><b>TOTAL AMOUNT:</b></i></legend>
<table border="0">
<tr>
<td colspan="2" align="left">
<form>
€ <input type="text" name="totalSum" id="totalSum" value="0" size="3" readonly="readonly">,00
</td>
</tr>
<tr>
<td align="left">
<button onclick="reset()">Clear all</button>
</form>
</td>
</tr>
</table>
</fieldset>
<p></p>
<fieldset>
<legend><i><b>Submit:</b></i></legend>
<table border="0">
<tr>
<td align="left">
<input type="submit" name="button" id="Button1">
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="SendMail()" />
<asp:TextBox ID="txtTotalAmount" runat="server" Text="18097 Rs.">
</td>
</tr>
</table>
</body>
</html>
What I have tried:
I've just tried to change the code but it still doesn't want to work...
推荐答案
I Hope this will work for you.At my end it is working fine.Thanks:)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SmartHOME</title>
<style>
body
{
background-image: url("");
background-color: #000000;
}
fieldset
{
background-color: #996b6b;
display: inline-block;
}
h1
{
text-shadow: 2px 2px #000000;
}
</style>
<body>
<script type="text/javascript">
function DisplayPrice(price) {
var val1 = 0;
for (i = 0; i < document.form1.price.length; i++) {
if (document.form1.price[i].checked == true) {
val1 = document.form1.price[i].value;
}
}
var val2 = 0;
for (i = 0; i < document.form2.price2.length; i++) {
if (document.form2.price2[i].checked == true) {
val2 = document.form2.price2[i].value;
}
}
var val3 = 0;
for (i = 0; i < document.form3.price3.length; i++) {
if (document.form3.price3[i].checked == true) {
val3 += parseInt(document.form3.price3[i].value);
}
}
var sum = parseInt(val1) + parseInt(val2) + parseInt(val3);
document.getElementById('totalSum').value = sum;
}
function reset() {
for (i = 0; i < document.form1.price.length; i++)
document.form1.price[i].checked = false;
for (i = 0; i < document.form2.price2.length; i++)
document.form2.price2[i].checked = false
for (i = 0; i < document.form3.price3.length; i++)
document.form3.price3[i].checked = false
document.getElementById('totalSum').value = '';
}
</script>
<script type="text/javascript">
function SendMailwithAmount() {
var txtTotalAmount = document.getElementById('totalSum').value;
alert(txtTotalAmount);
var link = "mailto:abc@abc.com" +
"?cc=abc@abc.com" +
"&subject=" + escape("This is subject and total amount is: " + txtTotalAmount) +
"&body=" + escape("This is body and total amount is: " + txtTotalAmount);
window.location.href = link;
}
</script>
</body>
<body>
<p>
</p>
<h1>
<font color="white"> SmartHOME</font></h1>
<p>
</p>
<fieldset>
<legend>Group 1:</legend>
<form name="form1" id="form1" runat="server">
<br>
<input id="rdo_1" type="radio" value="1000" name="price" onclick="DisplayPrice(this.value);">Choice
1 - € 1.000,00
<br>
<input id="rdo_2" type="radio" value="2000" name="price" onclick="DisplayPrice(this.value);">Choice
2 - € 2.000,00
<br>
<input id="rdo_3" type="radio" value="5000" name="price" onclick="DisplayPrice(this.value);">Choice
3 - € 5.000,00
<p>
</p>
</form>
</fieldset>
<p>
</p>
<fieldset>
<legend>Group 2:</legend>
<form name="form2" id="form2" runat="server">
<br>
<input id="rdo_1" type="radio" value="100" name="price2" onclick="DisplayPrice(this.value);">Choice
1 - € 100,00
<br>
<input id="rdo_2" type="radio" value="200" name="price2" onclick="DisplayPrice(this.value);">Choice
2 - € 200,00
<p>
</p>
</form>
</fieldset>
<p>
</p>
<fieldset>
<legend>Group 3:</legend>
<form name="form3" id="form3" runat="server">
<br>
<input id="rdo_1" type="checkbox" value="100" name="price3" onclick="DisplayPrice(this.value);">Choice
1 - € 100,00
<br>
<input id="rdo_2" type="checkbox" value="200" name="price3" onclick="DisplayPrice(this.value);">Choice
2 - € 200,00
<br>
<input id="rdo_1" type="checkbox" value="450" name="price3" onclick="DisplayPrice(this.value);">Choice
3 - € 450,00
<br>
<input id="rdo_1" type="checkbox" value="600" name="price3" onclick="DisplayPrice(this.value);">Choice
4 - € 600,00
<br>
<input id="rdo_1" type="checkbox" value="750" name="price3" onclick="DisplayPrice(this.value);">Choice
5 - € 750,00
<p>
</p>
</form>
</fieldset>
<p>
</p>
<fieldset>
<legend>TOTAL AMOUNT</legend>
<table border="0">
<tr>
<td colspan="2" align="left">
<form>
€
<input type="text" name="totalSum" id="totalSum" value="" size="3" readonly="readonly">
,00
</td>
</tr>
<tr>
<td align="left">
<button onclick="SendMailwithAmount()">
Submit </button>
//this is where I have to put the submit button
</td>
<td align="left">
<button onclick="reset()">
Clear all</button>
</form>
</td>
</tr>
</table>
</fieldset>
</body>
</html>
您好,
请找到以下解决方案。
按钮点击使用以下javascript功能。
Hi ,
Please find the below solution.
on button click use below javascript fuction.
function SendMail() {
var link = "mailto:abc@abc.com" +
"?cc=bcd@bcd.com" +
"&subject=" + escape("This is subject") +
"&body=" + escape("This is body here you can pass the Price data");
window.location.href = link;
}
这篇关于如何从提交按钮发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!