本文介绍了给定程序无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么此代码未运行
Why this code is not running
<%@ Page Language="C#" EnableSessionState="False" EnableViewState="False" Trace="False" Debug="True"%>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Net.Mail" %>
<script runat="server">
void send(Object sender, EventArgs e)
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress(t1.Text, t2.Text);
smtpClient.Host = "webmail.kamnatrust.com";
smtpClient.Port = 80;
message.From = fromAddress;
message.To.Add("[email protected]");
message.Subject = "Feedback";
message.IsBodyHtml = false;
message.Body = t3.Text;
smtpClient.Send(message);
l1.Text = "Email successfully sent.";
}
catch (Exception ex)
{
l1.Text = "Send Email Failed.<br>" + ex.Message;
}
}
}
</script>
<html>
<body>
<form runat="server">
<table>
<tr><td>
Enter Email<asp:TextBox ID="t1" runat="server"/><br>
Name <asp:TextBox ID="t2" runat="server"/>
<br>
Subject<asp:TextBox ID="t3" runat="server"/>
<br>
Click to send <asp:Button ID="b1" Text="send" OnClick="send" runat="server"/>
<br>
<asp:Label ID="l1" runat="server"/>
</br></br></br></br></td></tr>
</table>
</form>
</body>
</html>
</br>
推荐答案
这篇关于给定程序无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!