housetouror
09-02-2004, 02:13 AM
I pulled the following code off another thread. Can someone tell me why this email component sends two emails? It sends one for when the page loads(which obviously has no info because nothing has submitted at that point) and another after the submit button is clicked. I thought the If CheckFanEmailAddresses(FanEmail) = false Then would keep it from executing on the initial page load. If there's no explanation, can someone please reccommend a different code? Thank you.
Sub AddNewFanEmail(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FanEmail as String = txtEmailAddress.Text
If CheckFanEmailAddresses(FanEmail) = false Then
Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
mailMessage.From = "anyone@anywhere.net"
mailMessage.To = "scott@mapleleafmortgage.net"
mailMessage.Subject = "This is an email"
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
mailMessage.body = "The person's email is " & txtEmailAddress.text
System.Web.Mail.SmtpMail.SmtpServer = "localhost"
System.Web.Mail.SmtpMail.Send(mailMessage)
End If
End Sub
Sub AddNewFanEmail(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim FanEmail as String = txtEmailAddress.Text
If CheckFanEmailAddresses(FanEmail) = false Then
Dim mailMessage As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
mailMessage.From = "anyone@anywhere.net"
mailMessage.To = "scott@mapleleafmortgage.net"
mailMessage.Subject = "This is an email"
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
mailMessage.body = "The person's email is " & txtEmailAddress.text
System.Web.Mail.SmtpMail.SmtpServer = "localhost"
System.Web.Mail.SmtpMail.Send(mailMessage)
End If
End Sub