ASP.NET MVC 电子邮件联系表
我正在创建一个联系表单,供客户在表单中输入信息并向我们提交电子邮件。另外,我的托管包位于 GoDaddy 下。我使用以下代码作为测试并且它有效。
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 或 Sender 字段之一,但都没有找到
I am creating a contact form for customers to type info in the form and submit an email to us. Also, my hosting package is under Go Daddy. I used the following code as a test and it worked.
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);
Then I changed to code to get the info inputted from the form to be emailed, and not it's giving me an error.
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();
}
Its giving me this error
COMException (0x8004020d): At least one of the From or Sender fields is required, and neither was found
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您没有提供电子邮件发件人字段:
looks like you are not supplying the email-from field:
您指定的“发件人”字段不是有效的电子邮件地址。收件人和发件人必须采用电子邮件格式,即使它们不是可以发送或接收邮件的实时地址。
The "From" field you specified isn't a valid email address. To and from need to be in email format, even if they aren't live addresses that can send or receive mail.