这是一个非常简单的联系表单,只需在按钮单击事件上运行以下代码。问题是在网络内部这个东西工作得很好,但是当我在外面尝试时什么都没有发生,而是一个 500 服务器错误。特别奇怪的是,这在几天前还可以正常工作。我猜这可能是 DNS 发生的事情。我的问题是,我怎样才能阻止这种情况发生并使这种形式更稳定?
string toAddress = "me@me.com";
string fromAddress = "no-reply@mydomain.com";
string mailServer = "mail.mydomain.com";
DateTime now = DateTime.Now;
MailMessage myMailMessage = new MailMessage();
myMailMessage.To.Add(toAddress);
myMailMessage.From = new MailAddress(fromAddress);
myMailMessage.Subject = "Contact Form Submission";
myMailMessage.Body =
"some text" + "\r\n" +
"-------------------------------------------" +
"\r\n" +
"xxx#: " + xxx.Text.ToString() +
"\r\n" + "FirstName: " + FirstName.Text.ToString() +
"\r\n" + "LastName: " + LastName.Text.ToString() +
"\r\n" + "City: " + City.Text.ToString() +
"\r\n" + "ListPrice: " + ListPrice.Text.ToString() +
"\r\n" + "Features: " + Features.Text.ToString() +
"\r\n"
SmtpClient mySmtpClient = new SmtpClient(mailServer);
mySmtpClient.Send(myMailMessage);
Response.Redirect("thankyou.aspx");