Results 1 to 13 of 13

Thread: Duplicate messages sent to Webmaster

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Duplicate messages sent to Webmaster

    Hello

    When a user completes an online contact form, the details are sent to a Webmaster. Is there any reason, in the following code, why the Webmaster would receive those details in duplicate? In the email inbox, the user's email address is visible twice.

    This is not related to the email software that receives the user's email - I have tested it in Outlook and other leading
    brands.

    Code:
     Protected Sub SendEmail_Click(sender As Object, e As System.EventArgs) Handles SendEmail.Click
    
            Dim myMessage As New MailMessage
            Dim Smtpserver As New SmtpClient
    
                Dim user_name As String = Request.Form("user_name")
                Dim user_email As String = Request.Form("user_email")
                Dim user_subject As String = Request.Form("user_subject")
                Dim user_message As String = Request.Form("user_message")
    
                          myMessage.From = New MailAddress(user_email) 'User's email
                         myMessage.To.Add(New MailAddress("info@mysite.net")) 'Webmaster
    
                myMessage.Subject = user_subject
                myMessage.Body = user_message
                myMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
                myMessage.IsBodyHtml = True
                myMessage.Priority = MailPriority.High
    
                Smtpserver.DeliveryMethod = SmtpDeliveryMethod.Network
                Smtpserver.Host = ("IP_add")
                Smtpserver.Port = 25
                Smtpserver.EnableSsl = False
    
                Dim basicAuthenticationInfo As New System.Net.NetworkCredential("info@mysite.net", "pwd")
                Smtpserver.Credentials = basicAuthenticationInfo
                'Smtpserver.UseDefaultCredentials = False
                Smtpserver.Send(myMessage)
    
                myMessage.Dispose()
                myMessage = Nothing
                Smtpserver = Nothing
    
      
        End Sub
    Thanks!

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Duplicate messages sent to Webmaster

    Just for fun... change this:
    myMessage.Subject = user_subject
    to this:
    myMessage.Subject = "** " & user_subject & " **"

    and see what happens... see if you get one email with the asterics and one with out, or if both come with it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Re: Duplicate messages sent to Webmaster

    It comes out like this:

    **Test2msgs** (Test2 msgs was my subject when posting the form).

    The messages are sent in duplicate

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Duplicate messages sent to Webmaster

    I'm assuming you aren't double-clicking the SendEmail button.

    Do you have access to the SMTP server? Is logging enabled on the SMTP server? If so, have you looked at those logs?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Re: Duplicate messages sent to Webmaster

    No, not double-clicking! And no duplicate entries in a database. Web hosting service will have access to the SMTP server. What should I ask them to look for? Or to send me the logs and post them here?

  6. #6
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Duplicate messages sent to Webmaster

    For your SendEmail button, is your code perhaps triggering the click method twice?

    In your <asp:Button ...> definition for SendEmail, do you have something like OnClick="SendEmail_Click" defined? If so, that might cause the SendEmail_Click method to fire twice, once because it is set to handle the click event, and once because the button is set to call that method. If so, get rid of OnClick="SendEmail_Click" from the <asp:Button ...> definition and that should fix it.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Re: Duplicate messages sent to Webmaster

    I have this:

    Code:
    <asp:Button ID="SendEmail" runat="server" Text="[Send]" OnClick="SendEmail_Click" /></>
    When I didn't have that OnClick, I felt that the 'Send' button was depressing when clicked, but I can try it.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Re: Duplicate messages sent to Webmaster

    Seems to be OK. I will compile it without onClick and upload and post back.

  9. #9
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Duplicate messages sent to Webmaster

    Quote Originally Posted by SteveHi View Post
    I have this:

    Code:
    <asp:Button ID="SendEmail" runat="server" Text="[Send]" OnClick="SendEmail_Click" /></>
    When I didn't have that OnClick, I felt that the 'Send' button was depressing when clicked, but I can try it.
    Well, my advice there would be don't take button presses personally!

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Re: Duplicate messages sent to Webmaster

    The messages (I tried it x2) are not arriving. Logged in and out of email programme - still not arrived

  11. #11
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Duplicate messages sent to Webmaster

    That doesn't make sense. The OnClick piece of the button definition shouldn't be necessary when you have a method set to handle the button.Click event. Does anything happen when you click the button, like do you see the page refresh?

  12. #12
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Duplicate messages sent to Webmaster

    The next thing I would try is to put the
    Code:
    OnClick="SendEmail_Click"
    back into the button definition, but then remove the
    Code:
    Handles SendEmail.Click
    from the end of the Sub definition.

    That should ensure that the method is called via the OnClick functionality, but not because the .Click event is handled, which should call it only once.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Re: Duplicate messages sent to Webmaster

    I think I owe you a beer!
    That works!
    THANK YOU

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width