我正在为客户创建一个联系表格,以便在表格中输入信息并向我们提交电子邮件。此外,我的托管包在 Go Daddy 下。我使用以下代码作为测试并且它有效。
MailMessage oMail = new System.Web.Mail.MailMessage();
oMail.Subject = "Subject",
oMail.Body
oMail.From = "myFromAddress@domain.com",
oMail.To = "myToAddress@someotherdomain.com",
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 = "myemail@hmydomain.com";
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 或 Sender 字段中至少有一个是必需的,但都没有找到