我有一個表單的問題,我不能發送它。如果我提出錯誤的細節(安全代碼,電子郵件,空白字段等),我會在屏幕上看到錯誤,這是正確的。聯繫表格不起作用
但是,當我輸入正確的數據,我不能發送的形式,我得到這個錯誤:
There was an error submitting your form. Please check the following:
但列表爲空。
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress("[email protected]", "string1");
// decide who message goes to
string emailGoesTo = "[email protected]";
MailAddress toAddress = new MailAddress(emailGoesTo.ToString(), "string1");
message.From = fromAddress;
message.To.Add(toAddress);
message.To.Add("[email protected]");
message.Subject = "string2";
message.Body = "New Website Contact Request";
message.Body += "------------------------------------------\r\n";
message.Body += "Name: " + your_name.Text + "\r\n";
message.Body += "Email: " + your_email.Text + "\r\n";
message.Body += "Telephone: " + your_telephone.Text + "\r\n";
message.Body += "Company: " + your_company.Text + "\r\n";
message.Body += "Address: " + your_address.Text + "\r\n";
message.Body += "Postcode: " + your_zip.Text + "\r\n";
message.Body += "Enquiry: " + your_enquiry.Text + "\r\n";
// smtpClient.Host = "string3";
smtpClient.Host = "string4";
smtpClient.Credentials = new System.Net.NetworkCredential("string5", "string6");
smtpClient.Send(message);
Response.Redirect("thankyou.aspx");
}
catch (Exception ex)
{
statusLabel.Text = "Coudn't send the message!";
}
我noobie,所以有ANY1 string5
& string6
好嗎?
還有什麼問題?如何使這個表單工作?
你有沒有在調試過程中通過代碼,看看它在哪裏失敗?我的第一個猜測是格式或smtpclient.host的信息是錯誤的。如果你使用交換,你的電子郵件服務器需要允許從任何生成電子郵件的機器(你的ip進行測試)進行中繼,但通常不會發出錯誤,它只是不發送郵件。我已經添加了一個工作郵件發送的例子作爲答案,您可以從 – Brian 2012-08-06 15:36:00