-
Jan 18th, 2018, 02:51 PM
#1
Thread Starter
Hyperactive Member
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!
-
Jan 18th, 2018, 03:52 PM
#2
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
-
Jan 18th, 2018, 04:23 PM
#3
Thread Starter
Hyperactive Member
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
-
Jan 18th, 2018, 04:46 PM
#4
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?
-
Jan 18th, 2018, 04:51 PM
#5
Thread Starter
Hyperactive Member
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?
-
Jan 18th, 2018, 04:53 PM
#6
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.
-
Jan 18th, 2018, 04:56 PM
#7
Thread Starter
Hyperactive Member
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.
-
Jan 18th, 2018, 04:58 PM
#8
Thread Starter
Hyperactive Member
Re: Duplicate messages sent to Webmaster
Seems to be OK. I will compile it without onClick and upload and post back.
-
Jan 18th, 2018, 04:59 PM
#9
Re: Duplicate messages sent to Webmaster
Originally Posted by SteveHi
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!
-
Jan 18th, 2018, 05:16 PM
#10
Thread Starter
Hyperactive Member
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
-
Jan 18th, 2018, 05:31 PM
#11
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?
-
Jan 18th, 2018, 05:35 PM
#12
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.
-
Jan 18th, 2018, 06:06 PM
#13
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|