Hi there, I have a feedback form on my contact.aspx page which includes: full name, email address, phone #, subject (a drop-down list with 3 options), and the comments fields. When the user enters data and clicks submit, it's currently sending me their email address and the comments only. 1) I would also like to receive their name, phone# and the subject. Here's my VBcode: Imports System.Net.Mail.SmtpClient Partial Class contact Inherits System.Web.UI.Page Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate If txtComments.Text.Length > 5000 Then args.IsValid = False Else args.IsValid = True End If End Sub Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick SendMail(txtName.Text, txtEmail.Text, txtComments.Text) End Sub Private Sub SendMail(ByVal name As String, ByVal from As String, ByVal body As String) Dim mailServerName As String = "smtp.MyDomain.com" Dim message As MailMessage = New MailMessage(from, "[email protected]", "feedback", body) Dim mailClient As SmtpClient = New SmtpClient mailClient.Host = mailServerName mailClient.Send(message) message.Dispose() End Sub End Class 2) Once the user clicks submit, I'd like to display a confirmation that the email has been sent. How do I do this? Thanks in advance.AJ Post Edited By Moderator (mjp [DASP]) : 11/2/2007 8:57:13 PM GMT
You need to include the name and phone # in the message body itself. So, the third parameter in your method SendMail(txtName.Text, txtEmail.Text, txtComments.Text</font>) needs ,the name and phone # appended to it. For the confirmation part of it.You can have a js function in the such as follows: validate() { var EmailStatus= document.getElementById('stat'); alert(EmailStatus.value); if(StatusTable.value == '1') { Alert('Your Email has been sent') } } where stat is a hidden field on your form ,which you set it when the form is submitted successfully and have something like or simply have a label and populate the text from code behind. Vikram DiscountASP.NET www.DiscountASP.NET
Hi Vikram, I really appreciate your help; unfortunately, you're helping a dud... At any rate, I've tried other things which are incorrect. To include the name, phone#, and subject in the email, I tried 2 things: 1) Private Sub SendMail(ByVal name As String, ByVal phone As String, ByVal from As String, ByVal body As String) Dim feedbackinfo As String = name + phone + body Dim mailServerName As String = "smtp.MyDomain.com" Dim message As MailMessage = New MailMessage(from, "[email protected]", "feedback", feedbackinfo) Dim mailClient As SmtpClient = New SmtpClient and.................................. 2) Private Sub SendMail(ByVal name As String, ByVal phone As String, ByVal from As String, ByVal subject As String,ByVal body As String) Dim mailServerName As String = "smtp.MyDomain.com" Dim message As MailMessage = New MailMessage(from, "[email protected]", "feedback", name, phone, subject, body) Dim mailClient As SmtpClient = New SmtpClient No luck whatsoever. As for the confirmation msg, like I said, I'm a dud...a newbie if you will. I put the following between <asp:Content ID...> and <span style>: <script type="text/javascript"> validate() { var EmailStatus= document.getElementById("stat"); alert(EmailStatus.value); if(StatusTable.value == '1') { Alert("Your Email has been sent") } } where stat is a hidden field on your form ,which you set it when the form is submitted successfully and have something like </script> But I'm not getting any luck with what I'm trying to accomplish. Where can I put this js? Thanks again. AJ
See : http://kb.discountasp.net/article.aspx?id=10443 Replace body by Dim body As String = name + phone + body_part To keep things simple,for the confirmation,have a label on your page .After the mail is sent,set the label text to what ever you want. See: http://www.w3schools.com/aspnet/control_label.asp to know how to do that. For the js part,I see you added the comment 'where stat is a hidden field on your form ... within the script tags. i guess it was my mistake in my previous post...Sorry about that.That was just a comment. Vikram DiscountASP.NET www.DiscountASP.NET
Hi Vikram, Once again I appreciate your patience with me...but I'm really starting to lose my hair over this. I already took care of the confirmation msg...thanks for that. But I'm still only getting the email address and comments in my email. Here's my VB script: Imports System.Net.Mail.SmtpClient Partial Class contact3 Inherits System.Web.UI.Page Protected Sub submitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submitButton.Click SendMail(txtName.Text, txtEmail.Text, txtPhone.Text, txtComments.Text) txtName.Text = '' txtEmail.Text = '' txtComments.Text = '' txtPhone.Text = '' txtSubject.Text = '' End Sub Private Sub SendMail(ByVal name As String, ByVal phone As String, ByVal from As String, ByVal body As String) Dim body As String = name + phone + body_part Dim mailServerName As String = 'smtp.MyDomain.com' Dim message As MailMessage = New MailMessage(from, '[email protected]', 'feedback', body) Dim mailClient As SmtpClient = New SmtpClient mailClient.Host = mailServerName mailClient.Send(message) message.Dispose() End Sub End Class </font> I'm about to remove the drop-down menu for the subject to make things simpler, but this is what I'm getting: Compiler Error Message: BC30734: 'body' is already declared as a parameter of this method. Source Error: Line 18: Private Sub SendMail(ByVal name As String, ByVal phone As String, ByVal from As String, ByVal body As String) Line 19: Line 20: Dim body As String = name + phone + body_part Line 21: Dim mailServerName As String = 'smtp.MyDomain.com' Line 22: Dim message As MailMessage = New MailMessage(from, '[email protected]', 'feedback', body) </font> Pls help Vikram. Thanks again.
Hi AJ, If you want an Ajax Contact form, with validation, like this: http://www.sdknuts.net/contact/ Send me a note with a valid e-mail address and I'll send you my code. Salute, Mark