并非所有字段都是通过电子邮件发送 [英] Not all fields sent from email form
问题描述
我已经为此工作了很多天 - 以下页面仅在结果中发送电子邮件地址。有什么建议?
<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language =" c#" %>
<%@ Import Namespace =" System.Text" %>
<%@ Import Namespace =" System.Web.Mail" %>
< script type =" text / c#" runat =" server">
private void btnSend_Click(System.Object sender,System.EventArgs e)
{
//创建消息
StringBuilder sb = new StringBuilder( );; MailMessage msg1 = new MailMessage();
构建我们的消息
sb.Append(" From:");
sb.Append (txtFname.Text);
sb.Append("& nbsp;");
sb.Append(txtLname.Text);
sb.Append("< br />电子邮件:");
sb.Append(txtEmail.Text);
sb.Append("< br /> Phone:");
sb。附加(txtPhone.Text);
//设置from,to,subject等...
msg1.From = txtEmail.Text;
msg1.To = tbTo .Value;
msg1.Subject = tbSubject.Value;
msg1.Body = txtEmail.Text;
msg1.Priority = MailPriority.Normal;
SmtpMail.SmtpServer =" smtp .my-web-site.com" ;;
msg1.Fields.Add(" http://schemas.microso ft.com/cdo/configuration/smtpserver","smtp.my-web-site.com");
msg1.Fields.Add(" http://schemas.microsoft.com/cdo/configuration / smtpserverport",25);
msg1.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendusing" ;, 2);
msg1.Fields.Add(" ; http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ;, 1);
msg1.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendusername", " the-site-user-id");
msg1.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendpassword"," site-password");
更改视图以删除表格
MultiView1.ActiveViewIndex = -1;
试试
{
SmtpMail 。发送(msg1);
lblStatus.Text ="发送消息" ;;
抓住了
发送消息{
lblStatus.Text ="消息未发送" ;;
}
}< / script>< html xmlns =" http://www.w3.org/1999/xhtml">
< head>
< meta content =" zh -us" HTTP的当量= QUOT;内容语言与QUOT; />
< meta content =" text / html;字符集= UTF-8英寸HTTP的当量= QUOT;内容类型" />
< title> Untitled 2< / title>
< style type =" text / css">
body,tr,td {
font-家庭:Arial,Helvetica,sans-serif;
font-size:small;
}< / style>
< / head>
>< body>
< form id =" form1" runat =" server">
<! - 在此处设置您的收件人信息 - >
< asp:HiddenField runat =" server" ID = QUOT; TBTO"值= QUOT; my-email-user-name@hotmail.com"可见="假"> < / asp:HiddenField>
< ;! - 在此设置您的默认主题 - >
< asp:HiddenField runat =" server" ID = QUOT; tbSubject"值="新联系人">< / asp:HiddenField>
<! - 表格控件从这里开始--->
< br />
< asp:标签runat =" server"文字="在下面填写您的信息:" id =" lblStatus">< / asp:Label>
< br />
< br />
< br />
< ; asp:MultiView id =" MultiView1" RUNAT = QUOT;服务器" ActiveViewIndex =" 0">
< asp:View id =" View1" runat =" server">
< table align =" center" style =" width:250px">
< tr>
< td>名字:< / td>
< td>
< asp: requiredfieldvalidator id =" RequiredFieldValidator1" RUNAT = QUOT;服务器"的ControlToValidate = QUOT; txtFname" ErrorMessage =" First Name is Required">< / asp:requiredfieldvalidator>
< asp:textbox id =" txtFname" runat =" server">< / asp:textbox>
< / td>
< / tr>
< tr>
< td>最后名称:< / td>
< td>
< asp:textbox id =" txtLname" runat =" server">< / asp:textbox>
< / td>
< / tr>
< tr>
< td>电子邮件地址:< / td>
< td>
< asp:textbox id =" txtEmail" runat =" server">< / asp:textbox>
< / td>
< / tr>
< tr>
< td>电话号码:< / td>
< td>
< asp:textbox id =" txtPhone" runat =" server">< / asp:textbox>
< / td>
< / tr>
< tr>
< td>& ;< / td>
< td>
< asp:button id =" Button1" RUNAT = QUOT;服务器"的onClick = QUOT; btnSend_Click"文字="发送表格" />
< / td>
< / tr>
< / table>
< / asp:查看>
< / asp: MultiView>
< / form>
< / body>
< / html>
I have worked on this for many days - the following page only sends the email address in the result. any suggestions?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="c#" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Web.Mail" %>
<script type="text/c#" runat="server">
private void btnSend_Click(System.Object sender, System.EventArgs e)
{
//Creates the message
StringBuilder sb = new StringBuilder();
MailMessage msg1 = new MailMessage();
//build our message
sb.Append("From:");
sb.Append(txtFname.Text);
sb.Append(" ");
sb.Append(txtLname.Text);
sb.Append("<br />Email:");
sb.Append(txtEmail.Text);
sb.Append("<br />Phone:");
sb.Append(txtPhone.Text);
//Sets the from, to, subject, etc...
msg1.From = txtEmail.Text;
msg1.To = tbTo.Value;
msg1.Subject = tbSubject.Value;
msg1.Body = txtEmail.Text;
msg1.Priority = MailPriority.Normal;
SmtpMail.SmtpServer = "smtp.my-web-site.com";
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver","smtp.my-web-site.com");
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing",2);
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1);
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","the-site-user-id");
msg1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","site-password");
//Change the view to remove the form
MultiView1.ActiveViewIndex = -1;
try
{
SmtpMail.Send(msg1);
lblStatus.Text = "Message sent";
}
catch
{
lblStatus.Text = "Message not sent";
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 2</title>
<style type="text/css">
body, tr, td {
font-family: Arial, Helvetica, sans-serif;
font-size: small;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<!-- Set your recipient info here -->
<asp:HiddenField runat="server" id="tbTo" Value="my-email-user-name@hotmail.com" Visible ="false"> </asp:HiddenField>
<!-- Set your default subject here -->
<asp:HiddenField runat="server" id="tbSubject" Value="New Contact"></asp:HiddenField>
<!-- Form controls start here --->
<br />
<asp:Label runat="server" Text="Fill out your information below:" id="lblStatus"></asp:Label>
<br />
<br />
<br />
<asp:MultiView id="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View id="View1" runat="server">
<table align="center" style="width: 250px">
<tr>
<td>First Name:</td>
<td>
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" ControlToValidate="txtFname" ErrorMessage="First Name is Required"></asp:requiredfieldvalidator>
<asp:textbox id="txtFname" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>Last Name:</td>
<td>
<asp:textbox id="txtLname" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>Email Address:</td>
<td>
<asp:textbox id="txtEmail" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td>Phone Number:</td>
<td>
<asp:textbox id="txtPhone" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:button id="Button1" runat="server" onClick="btnSend_Click" Text="Send Form" />
</td>
</tr>
</table>
</asp:View>
</asp:MultiView>
</form>
</body>
</html>
推荐答案
由于这一行:
msg1.Body = txtEmail.Text;
它表示将电子邮件的正文作为表单上的电子邮件字段。
更改为:
msg1.Body = sb.toString();
Because of this line:
msg1.Body = txtEmail.Text;
It says to make the body of the email the email field on your form.
Change to:
msg1.Body = sb.toString();
这篇关于并非所有字段都是通过电子邮件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!