quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

Last post 07-06-2009 1:29 AM by venkatu2005. 14 replies.

Sort Posts:

  • quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    06-28-2009, 7:42 AM
    • Member
      11 point Member
    • nadude
    • Member since 05-15-2009, 8:41 PM
    • Posts 27

    Using VWD08, and asp.net 3.5 vb.

    I have a contact us form  on a page, done through a wizard. (Followed the steps of a video tutorial on asp.net). Then added some code for using gmail/smtp.

    The wizards first step has two text boxes which request users name and address (txtName and txtEmail). Then the second page, before complete which triggers a finish button click to send mail. Second page has a text box again with the body of the message (txtMessage).

    When i recieve the email, the body comes through, but there is no sign of the name or email. Any ideas on whats going wrong? Not used to VB, so I know its probably just a tiny bit of code missing. I tried a bunch of googling, searching and trying to hack vb code to join the textbox values at the least, couldnt get it done... Would really appreciate if anyone points out whats wrong... ?

    Maybe its because of gmail smtp, i cant put a from email address other than the account being used. In that case can someone give me how to connect the three txtbox values with space inbetween, so i make that the updated txtBody, then it will be in the email ? I don't know... HELP PLEAAASE :)

     

    This is my script:

    <%@ Page Title="Contact Us" Language="VB" MasterPageFile="~/LayoutMasterPage.master" %>
    
    <%@ Import Namespace="System.Net.Mail" %>
    
    <script runat="server">
    
        Protected Sub wzContact_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs)
                   
            SendMail(from:=txtEmail.Text, body:=txtMessage.Text)
            
        End Sub
            
        
        Private Sub SendMail(ByVal from As String, ByVal body As String)
            Dim mailServerName As String = "smtp.gmail.com"
            Dim message As MailMessage = New MailMessage(from, "myemailaddress@gmail.com", "Feedback from Website", body)
            Dim mailClient As SmtpClient = New SmtpClient
            
            
            mailClient.Host = mailServerName
            mailClient.EnableSsl = True
            mailClient.Send(message)
            message.Dispose()
        End Sub
        
    </script>
     
     
    And this is the wizard steps: 
     
    <asp:Wizard ID="wzContact" runat="server" ActiveStepIndex="0" Width="700px" 
                    Height="300px" CellPadding="20" 
                    onfinishbuttonclick="wzContact_FinishButtonClick">
                <StepStyle VerticalAlign="Top" />
                <WizardSteps>
                    <asp:WizardStep runat="server" Title="Contact Info">
                        <table cellpadding="10" class="style1">
                            <tr>
                                <td>
                                    Your Name</td>
                                <td>
                                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                        ControlToValidate="txtName" ErrorMessage="Please enter your name">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Email</td>
                                <td>
                                    <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                        ControlToValidate="txtEmail" ErrorMessage="Please enter your email address">*</asp:RequiredFieldValidator>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                                        ControlToValidate="txtEmail" 
                                        ErrorMessage="Please enter a valid email address (user@domain.com)" 
                                        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
                                </td>
                            </tr>
                        </table>
                    </asp:WizardStep>
                    
                    <asp:WizardStep runat="server" StepType="Finish" Title="Message">
                        <table cellpadding="10" class="style1">
                            <tr>
                                <td align="left" class="style2" valign="top">
                                    Message</td>
                                <td class="style3">
                                    <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Height="80%" 
                                        Width="80%" ToolTip="Prototype error: Repeat email and name please">Prototype error: Please reenter email and name here.</asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                                        ControlToValidate="txtMessage" ErrorMessage="Please type your message">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:ValidationSummary ID="ValidationSummary2" runat="server" />
                                </td>
                            </tr>
                        </table>
                    </asp:WizardStep>
                    <asp:WizardStep runat="server" StepType="Complete" Title="Complete">
                        <table cellpadding="10" class="style1">
                        <tr><td align="center" valign="middle">Thank you, your message has been sent.</td></tr>
                        </table>
                    
                    </asp:WizardStep>
                </WizardSteps>
                <SideBarStyle HorizontalAlign="Left" VerticalAlign="Top" Width="100px" />
            </asp:Wizard>


     

     

     

  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    06-28-2009, 1:33 PM
    • Contributor
      7,249 point Contributor
    • whighfield
    • Member since 01-02-2006, 10:37 PM
    • Winterpeg, Manitoba
    • Posts 1,205

    Gmail does not use a standard SSL port so you need to set that, also there is an issue with the .NET SMTP client and sending over SSL and credentials see the following article, it will point you in the correct direction

    http://www.codeproject.com/KB/aspnet/aspnetemailusinggmail.aspx 

    Please mark the most helpful reply/replies as "Answer".

    - William
    http://thefrozencoder.ca
  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    06-29-2009, 12:50 AM
    • All-Star
      21,032 point All-Star
    • venkatu2005
    • Member since 07-01-2008, 6:48 AM
    • Posts 4,572

    Could you make clear ?  you mean you didnt get the email check it pls

    http://venkat-dotnetsamples.blogspot.com/2009/06/send-email-using-vbnet.html

    I have Changed My Blog from (http://venkat-dotnetsamples.blogspot.com) to (http://venkat-dotnetsnippets.blogspot.com)

    Regards,
    Venkatesan.M

    Please Mark as Answered If its helpful and Un-Mark as Answered if it not help u.
  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    06-29-2009, 4:35 AM
    • Member
      11 point Member
    • nadude
    • Member since 05-15-2009, 8:41 PM
    • Posts 27

     Hi guys, thanks for your replies. Just to make it clear I do recieve the email, I have configured my web.config file with some smtp code related to gmail. I have set up an account for the site, and stuck the username and password there. So all emails from the site system come from one gmail account.

    Lets say the gmail address for the site sitealert@gmail.com. when the email comes to me, it comes as from sitealert@gmail.com, and has the message, but not the name/email address of the user who sent the message from teh contact us wizard.

    i want the same gmail account used, but i want the custom name/email address options to be included in the email i recieve from sitealert@gmail.com . They can be in the subject or in the body, but i need them.

    Don't worry if you can't solve this problem, for now I just got rid of the name/email parts of the form, and put a message next to the body textbox saying if you want a reply remember to include your name and email address... temp work around for now...

  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    06-29-2009, 5:02 AM
    • All-Star
      21,032 point All-Star
    • venkatu2005
    • Member since 07-01-2008, 6:48 AM
    • Posts 4,572

    nadude:
    Lets say the gmail address for the site sitealert@gmail.com. when the email comes to me, it comes as from sitealert@gmail.com, and has the message, but not the name/email address of the user who sent the message from teh contact us wizard.

    You have to specify Explicitly Name / Email Address of the user and Message etc.. all should be concatenated to Mail Body .

    I have Changed My Blog from (http://venkat-dotnetsamples.blogspot.com) to (http://venkat-dotnetsnippets.blogspot.com)

    Regards,
    Venkatesan.M

    Please Mark as Answered If its helpful and Un-Mark as Answered if it not help u.
  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    07-01-2009, 3:36 PM
    • Member
      11 point Member
    • nadude
    • Member since 05-15-2009, 8:41 PM
    • Posts 27

    venkatu2005:
    You have to specify Explicitly Name / Email Address of the user and Message etc.. all should be concatenated to Mail Body .
     

    Sorry, I've no clue how to code to concatenate that stuff into the Mail Body. I've got them in three variable id's txtEmail, txtName and txtMessage. I'm using vb, how do i concatenate those three into one?

  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    07-02-2009, 12:24 AM
    Answer
    • All-Star
      21,032 point All-Star
    • venkatu2005
    • Member since 07-01-2008, 6:48 AM
    • Posts 4,572

    see this is my samle here i am concatenate the email,name message to Mail.Body

    Imports System.Net.Mail
    
    Protected  Sub Button1_Click
    (ByVal sender As Object, ByVal e As EventArgs)
    Dim mail As MailMessage =  New MailMessage()
    mail.To.Add(admin@gmail.com")
    mail.From = New MailAddress(admin@gmail.com")
    mail.Subject = "Email using Gmail server "
    
    dim  Body as string = "Hi, this mail is to test sending mail" &
                 "using Gmail in ASP.NET using vb.Net" & " Your email is " & txtEmail.Text &"<br/>Your name" & txtName.Text & "<br/> Yor Message " & txtMessage.Text
    mail.Body = Body
    
    mail.IsBodyHtml = True
    Dim smtp As SmtpClient =  New SmtpClient()
    smtp.Host = "smtp.gmail.com"
    smtp.Credentials = New System.Net.NetworkCredential
        ("YourUserName@gmail.com","YourGmailPassword")
    smtp.EnableSsl = True
    smtp.Send(mail)
    End Sub


    I have Changed My Blog from (http://venkat-dotnetsamples.blogspot.com) to (http://venkat-dotnetsnippets.blogspot.com)

    Regards,
    Venkatesan.M

    Please Mark as Answered If its helpful and Un-Mark as Answered if it not help u.
  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    07-03-2009, 7:10 AM
    • Member
      11 point Member
    • nadude
    • Member since 05-15-2009, 8:41 PM
    • Posts 27

    thanks, that looks great, and i'll save a reference to it for use later... for now i need to move on to add other functions, also regarding email... have two questions..

    1. since my gmail username and password are already in web.config, do i have to include them above like in your code? cant i just exclude those parts?

    2. on another page, i have a create message form, where one user can send another user a message (a db table), referenced by username... when they select a to username, i access the to users email address in a unvisible drop down list by sql.

    how can i change the above code, to use the variable id "DropDownList1" from teh page, to select the to: email address?  

  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    07-03-2009, 7:22 AM
    • All-Star
      21,032 point All-Star
    • venkatu2005
    • Member since 07-01-2008, 6:48 AM
    • Posts 4,572

    nadude:
    1. since my gmail username and password are already in web.config, do i have to include them above like in your code? cant i just exclude those parts?

    If you specify the username , password on your web.config file there is no need to provide in the code .

    nadude:
    2. on another page, i have a create message form, where one user can send another user a message (a db table), referenced by username... when they select a to username, i access the to users email address in a unvisible drop down list by sql.

    Here first you are bind the username to Dropdownlist at the time Bind the Username to DataTextField and Email to DataValueField so when the user choose the username

    using Dropdownlist1.SelectedValue you can get his emailID  then as usual pass the ID to To Address follow as like above

    Suppose, if you are binding only the username to Dropdownlist for both Datavaluefield and DataTextfield , at this time you have to retrieve the user emailID by using the username ie:on DropdownlistSelectedIndex_Changed Event or sumbit event then as do .

    If you have any query let me know..

    I have Changed My Blog from (http://venkat-dotnetsamples.blogspot.com) to (http://venkat-dotnetsnippets.blogspot.com)

    Regards,
    Venkatesan.M

    Please Mark as Answered If its helpful and Un-Mark as Answered if it not help u.
  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    07-03-2009, 7:45 AM
    • Member
      11 point Member
    • nadude
    • Member since 05-15-2009, 8:41 PM
    • Posts 27

     woooooooooohooooooooooooooooooo got it to work beautifully, thank you soooooooooooo much!!! just needed the .selectedvalue stuff... heres is the code

    Dim mail As MailMessage = New MailMessage()
            mail.[To].Add(DropDownList1.SelectedValue)
            mail.From = New MailAddress("myusername@gmail.com")
            mail.Subject = "New message recieved "
    
            Dim Body1 As String = "Hi, you've recieved a new message on MYSITE, please login and check your messages."
            mail.Body = Body1
            mail.IsBodyHtml = True
            Dim smtp As SmtpClient = New SmtpClient()
            smtp.EnableSsl = True
            smtp.Send(mail)

     

    i can't change the value of the username drop down to email, because i use the value of their username to send them a message in their database table. so i have to use another control to bring their email address , for now i made the email address visible.

    i had also put visible=false for the dropdownlist1, because i dont want users to see the email addresses of other users. do you know which control i could use to load such a field on a page,but hide it from the users? so that it can have a id.selectedvalue ?

    and one last super quick question.... the body string - "you've recieved a new message on mysite, please login and check your messages." how can I add an html url link to it so that MYSITE is a link?

  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    07-03-2009, 7:53 AM
    • All-Star
      21,032 point All-Star
    • venkatu2005
    • Member since 07-01-2008, 6:48 AM
    • Posts 4,572

    nadude:
    do you know which control i could use to load such a field on a page,but hide it from the users? so that it can have a id.selectedvalue ?

    for this pass the selectedvalue to hiddenfield so its default not visible to user so you can call hidden field as Hiddenfield1.Value

    nadude:
    body string - "you've recieved a new message on mysite, please login and check your messages." how can I add an html url link to it so that MYSITE is a link?

    for this add the anchor tag redirect you website

    <a href="http://www.servername.com/Login.aspx" target="_blank"> Login Here </a>


    I have Changed My Blog from (http://venkat-dotnetsamples.blogspot.com) to (http://venkat-dotnetsnippets.blogspot.com)

    Regards,
    Venkatesan.M

    Please Mark as Answered If its helpful and Un-Mark as Answered if it not help u.
  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    07-03-2009, 9:11 AM
    • Member
      11 point Member
    • nadude
    • Member since 05-15-2009, 8:41 PM
    • Posts 27

    not sure how to set the value for the hiddenfield. the dropdown has a sqldatasource, and value option, but the the hidden field doesnt... so just using the drop down list option for now...

     

    as for the embedding the anchor link, it gives a compilation error, end of statement expected, and the source error is:

     Dim Body1 As String = "Hi, you've recieved a new message on <a href="http://www.servername.com/Members/Messages.aspx" target="_blank"> Site </a> , please login and check your messages."
    Line 36:         mail.Body = Body1
    Line 37:         mail.IsBodyHtml = True

  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    07-04-2009, 2:00 AM
    • All-Star
      21,032 point All-Star
    • venkatu2005
    • Member since 07-01-2008, 6:48 AM
    • Posts 4,572

    nadude:
    not sure how to set the value for the hiddenfield. the dropdown has a sqldatasource, and value option, but the the hidden field doesnt... so just using the drop down list option for now

    To set the dropdownlist to hiddenfield like this

    HiddenField1.Value=Dropdownlist1.SelectedValue;

    Let me know where you want to hide or disable the Dropdownlist ie: on which page and what the reason to disable..

    nadude:
     Dim Body1 As String = "Hi, you've recieved a new message on <a href="http://www.servername.com/Members/Messages.aspx" target="_blank"> Site </a> , please login and check your messages."
    Line 36:         mail.Body = Body1
    Line 37:         mail.IsBodyHtml = True

    Try this

    Dim Body1 As String = "Hi, you've recieved a new message on <a href='http://www.servername.com/Members/Messages.aspx' target='_blank'> Site </a> , please login and check your messages."


    I have Changed My Blog from (http://venkat-dotnetsamples.blogspot.com) to (http://venkat-dotnetsnippets.blogspot.com)

    Regards,
    Venkatesan.M

    Please Mark as Answered If its helpful and Un-Mark as Answered if it not help u.
  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    07-04-2009, 6:42 AM
    • Member
      11 point Member
    • nadude
    • Member since 05-15-2009, 8:41 PM
    • Posts 27

    hey, thank you sooo much!!! i hate when its just such a small difference in syntax that makes the difference!!! it worked like magic!!! Laughing

    venkatu2005:
    Let me know where you want to hide or disable the Dropdownlist ie: on which page and what the reason to disable..
     

     

    as for the hiddenfield reason, ok i'll try explaining, hope i don't confuse you.

    1. main purpose of the site is for users to communicate to each other privately (messages), without disclosing their email addresses to each other for privacy reasons. so they should be able to pick a username, and then send a message, without seeing/knowing the selected user's email

    2. the way i've got the message db table, sql query and page working so far is like this:

    subject, message, from(userid), and to(username) are inserted to the table from the page. TO is selected from a dropdownlist of all users. and message gets stored in the table. when the other user logs in, their messages page, does a select where their username is in the to field so only their messages show on the page. ALL THIS IS WORKING FINE.

    3. now i just wanted to add an email alert to the "To user" saying they've recieved a new message on the site. which i got working with your help. the email address in the sendbutton_click value is set to dropdownlist1.selectedvalue

    - the dropdownlist1 sqlsource, selects username, and useremail address where username = ToUser. (ToUser is teh id of the to user select dropdown)

    - to user dropdown is on autopostback, so when that changes, it automatically changes teh value of teh dropdownlist1 to the selected user's email address.

    - which gives the value of the to email address for the send mail.

    all the above works perfectly, except for teh initial requirement of user email address privacy.  as the second dropdownlist1 (with to users email), is visible to the logged in user.

    4. i know i could go back and change the messages and compose pages sql queries to use useremail address instead of username, but that is too much sql editing for me, and i got lucky getting it to work the first time.

    so i just need a different hidden control on the field that has its own sql source, that gets its value changed everytime a new user is selected in todropdownlist - to be the value of the (select username and useremail where username = todropdown)

    hope that makes sense?

  • Re: quick email- Contact Us Form - Name/Email isn't coming through from 1st wizard step

    07-06-2009, 1:29 AM
    • All-Star
      21,032 point All-Star
    • venkatu2005
    • Member since 07-01-2008, 6:48 AM
    • Posts 4,572

    nadude:

    address instead of username, but that is too much sql editing for me, and i got lucky getting it to work the first time.

    so i just need a different hidden control on the field that has its own sql source, that gets its value changed everytime a new user is selected in todropdownlist - to be the value of the (select username and useremail where username = todropdown)

    hope that makes sense?

    As i said you are binding Username and email to dropdownlist so how the other users know his/ her email ID

    Your Dropdownlist1.DataTextField="Username:

    Dropdownlist1.DataValueField="Email" 

    like this you have to bind data you your dropdownlist so when the user chooses the username he / she knows only the username but not the EmailID because it has been bind it on selectedvaluefield. I think you understand. Further you have any query let me know..

    I have Changed My Blog from (http://venkat-dotnetsamples.blogspot.com) to (http://venkat-dotnetsnippets.blogspot.com)

    Regards,
    Venkatesan.M

    Please Mark as Answered If its helpful and Un-Mark as Answered if it not help u.
Page 1 of 1 (15 items)