我正在創建聯繫表單,供客戶在表單中輸入信息並向我們提交電子郵件。另外,我的託管軟件包在Go Daddy下。我用下面的代碼作爲測試,它工作。ASP.NET MVC電子郵件聯繫表
MailMessage oMail = new System.Web.Mail.MailMessage();
oMail.Subject = "Subject",
oMail.Body
oMail.From = "[email protected]",
oMail.To = "[email protected]",
SmtpMail.SmtpServer = "relay-hosting.secureserver.net";
SmtpMail.Send(oMail);
然後,我改變了代碼,以獲得從表格輸入的信息通過電子郵件發送,而不是它給了我一個錯誤。
public ActionResult ContactForm(ContactModel emailModel)
{
MailMessage oMail = new System.Web.Mail.MailMessage();
oMail.From = "Website Contact Form";
oMail.To = "[email protected]";
oMail.Subject = emailModel.Subject;
string body = "Name: " + emailModel.Name + "\n"
+ "Email: " + emailModel.Email + "\n"
+ "Website: " + emailModel.Website + "\n"
+ "Phone: " + emailModel.Phone + "\n\n"
+ emailModel.Message;
oMail.Body = body;
SmtpMail.SmtpServer = "relay-hosting.secureserver.net";
SmtpMail.Send(oMail);
return View();
}
它給我這個錯誤
收到COMException(0x8004020d):至少從或發件人的領域之一是必需的,沒有發現
嘗試在測試中使用的'From'和'To'。 – gdoron 2012-01-31 18:59:24