|
This works for me:
Dont forget this reference
Imports System.net.Mail
This is the code behind:
Private Sub ClearControls()
ddlContact.SelectedIndex = 0
txtMessage.Text = ""
txtName.Text = ""
txtEmail.Text = ""
txtPhone.Text = ""
End Sub
Private Sub SendMessage()
Try
Dim emFrom As String = txtEmail.Text
Dim emTo As String = ddlContact.SelectedValue
Dim MailObj As New MailMessage
MailObj.From = New MailAddress(emFrom)
MailObj.To.Add(emTo)
MailObj.Body = ("From:" & txtName.Text & "<br>" & " Message: " & txtMessage.Text)
MailObj.IsBodyHtml = True
Dim smtp As New SmtpClient("whatever your hosting provider gives you")
smtp.Send(MailObj)
ClearControls()
lblMessage.Visible = True
lblMessage.Text = "Thank you for your message! We will be in contact with you as soon as possible."
Catch
lblMessage.Text = "We are sorry but your message did not go through. Please call us for assistance @ 555-555-5555."
End Try
End Sub
Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnClear.Click
Response.Redirect("Contact.aspx")
End Sub
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSend.Click
Page.Validate()
If Page.IsValid Then
SendMessage()
End If
End Sub
|