[RESOLVED] [02/03] "Object reference not set to an instance of an object."
I don't know why it's saying this when I try to have the data emailed to me, I copied the code from a working form that I just did.
vb Code:
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If Not emailit() Then
lblResult.Text = "Error generated during form processing. Please try again."
End If
End Sub
Public Function emailit() As Boolean
Dim sent_ok = False
Try
Dim str As StringBuilder = New StringBuilder
Dim m As Mail.MailMessage = New Mail.MailMessage
m.To = "email"
m.From = txtEmail.Text
m.Priority = Mail.MailPriority.High
m.Subject = "Open House Form"
Dim body As String
body &= "Open House" & vbCrLf & vbCrLf
body &= "First Name: " & txtFirst.Text & vbCrLf
body &= "Last Name: " & txtLast.Text & vbCrLf
body &= "Address: " & txtAddress1.Text & " " & txtAddress2.Text & vbCrLf
body &= "City: " & txtCity.Text & vbCrLf
body &= "State: " & ddlStates.SelectedValue & vbCrLf
body &= "ZIP: " & txtZIP.Text & vbCrLf
body &= "Phone: " & txtAreaCode.Text & txtPhone.Text & vbCrLf
m.Body = body
'cc sender so they have a copy
' m.Cc = eventClass.ContactEmail
m.Headers.Add("Priority", "high")
Mail.SmtpMail.SmtpServer = "localhost"
Mail.SmtpMail.Send(m)
lblResult.Text = "Thank you, someone will contact you shortly."
sent_ok = True
Catch ex As Exception
sent_ok = False
Dim merror As Mail.MailMessage = New Mail.MailMessage
merror.To = "email"
merror.From = "email"
merror.Subject = "Event Error"
merror.Body = ex.Message
Mail.SmtpMail.SmtpServer = "localhost"
Mail.SmtpMail.Send(merror)
End Try
Return sent_ok
End Function
End Class
It detects an error and sends me the message, and the message just says "Object reference not set to an instance of an object.". Everything is the same as the working form I copied it from, other than a few fields that I deleted.
EDIT: Fixed it, missed one last stupid error.
Re: [RESOLVED] [02/03] "Object reference not set to an instance of an object."
When I find the guy that keeps spreading those nasty rumours that we're clairvoyant.... I'm going to have a few words....
Might help to know what line the error happens on....
-tg
Re: [RESOLVED] [02/03] "Object reference not set to an instance of an object."
Oh... I get it.... were you expecting something more.... it gave you what you asked... the ex.message.... if you want FULL details... try ex.ToString instead.
-tg