1

我正在尝试制作反馈表,但以前从未这样做过。我找到了一个在 VB 中解释它的教程,但即使代码对他有用,它似乎对我不起作用。失败后,我又尝试了另一个教程,但仍然不行!但由于第一个看起来更简单,我决定再试一次。有人可以通过向我解释我做错了什么来帮助我吗?

我有 4 个文本框Name, Email,TelephoneComments

错误似乎是由

Dim message As MailMessage = New MailMessage(from, "jaun@bulldogbroadband.co.za", "feedback", body)

错误:指定的字符串不是电子邮件地址所需的格式。

教程:[我如何:] 创建“联系我们”页面?

Protected Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
    SendMail(txtName.Text, txtEmail.Text)
    SendMail(txtTel.Text, txtComments.Text)
End Sub
Private Sub SendMail(ByVal from As String, ByVal body As String)
    Dim mailServerName As String = "SMTP.bulldogbroadband.co.za"
    Dim message As MailMessage = New MailMessage(from, "jaun@bulldogbroadband.co.za", "feedback", body)
    Dim mailClient As SmtpClient = New SmtpClient

    mailClient.Host = mailServerName
    mailClient.Send(message)
    message.Dispose()
End Sub
4

2 回答 2

0

我认为它失败了,因为“发件人”地址不是有效的电子邮件地址。此外,您调用 SendMail 两次,第二次使用电话号码和评论作为参数。

于 2013-03-15T17:51:06.300 回答
0

修复了它,仍然不明白出了什么问题,因为电子邮件地址是有效的,我不知道我是否可以这样做,但我要粘贴我当前使用的代码,因为它似乎是堆栈溢出有非常严格的规则

Imports System.Net.Mail
Imports System.Text
Partial Class ContactUs

Inherits System.Web.UI.Page

Protected Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
    Dim body As String = "From: " + txtName.Text + Environment.NewLine +_
 "Email: " + txtEmail.Text + Environment.NewLine + "Contact Number: " +_
 txtTel.Text + Environment.NewLine + Environment.NewLine + txtComments.Text

    Dim MM As New System.Net.Mail.SmtpClient
    MM.Host = "mail.bulldogbroadband.co.za"
    Dim cred As New System.Net.NetworkCredential("jaun@bulldogbroadband.co.za", "1@2345")
    MM.Credentials = cred
    MM.Send(txtEmail.Text, "jaun@bulldogbroadband.co.za", "feedback form", body)

    Response.Redirect("ThankYou.aspx")

End Sub

结束类

于 2013-03-17T18:35:52.217 回答