ASP.NET MVC 电子邮件联系表

发布于 2025-01-01 07:24:52 字数 1652 浏览 1 评论 0原文

我正在创建一个联系表单,供客户在表单中输入信息并向我们提交电子邮件。另外,我的托管包位于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

合约呢 2025-01-08 07:24:52

看起来您没有提供电子邮件发件人字段:

oMail.From = "[email protected]"; //instead of -> "Website Contact Form"

looks like you are not supplying the email-from field:

oMail.From = "[email protected]"; //instead of -> "Website Contact Form"
生生漫 2025-01-08 07:24:52

您指定的“发件人”字段不是有效的电子邮件地址。收件人和发件人必须采用电子邮件格式,即使它们不是可以发送或接收邮件的实时地址。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文