我正在尝试制作一份反馈表,但之前从未这样做过。我找到了一个在VB中解释它的教程,但即使代码适用于他,它似乎对我没有用。失败后,我尝试了另一个教程,仍然没有去!但由于第一个看起来更简单,我决定再试一次。有些人可以帮我解释一下我做错了什么吗?
我有4个文本框Name
,Email
,Telephone
和Comments
错误似乎是
Dim message As MailMessage = New MailMessage(from, "jaun@bulldogbroadband.co.za", "feedback", body)
错误:指定的字符串不是电子邮件地址所需的格式。
教程:[How Do I:] Create a "Contact Us" Page?
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
答案 0 :(得分:0)
我认为它失败了,因为'from'地址不是有效的电子邮件地址。 你也是两次拨打SendMail,第二次用电话号码和评论作为参数。
答案 1 :(得分: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
结束班