Question

I'm trying to make an feedback form, but have never done this before. I found a tutorial that explains it in VB but even though the code works for him it doesn't seem to work for me. After failing, I tried yet another tutorial and still no go! But since the first one looks simpler, I decided to try it again. Can some please help me by explaining to me what I did wrong?

I have 4 textboxes Name, Email, Telephone and Comments

The error seems to be by

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

error: The specified string is not in the form required for an e-mail address.

tutorial: [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
Was it helpful?

Solution 2

Fixed it, still don't understand what went wrong because the email address is valid, and I don't know if I'm allowed to do this but i'm gonna paste the code that I am currently using, because it seems stack overflow has very strict rules

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

End Class

OTHER TIPS

I think it's failing because the 'from' address isn't a valid email address. Also you're calling SendMail twice, the second time with telephone number and comments as parameters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top