Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Sir,

I just try to make a website and i got problem to send mail in contact us page.
My page is as follows :

Name : your name
Age : your age
Sex : your sex
Mobile : mobile
Email Id : your mailid
Description : your question

Submit


I want when someone click on submit button by filling all infos, all the information should send to my mail id. Please help me for this asap.
Posted

 
Share this answer
 
Try this..:)

.aspx page...:)

C#
<div>
<table>
            <tr>
                <td>
                    Your name:
                </td>
                <td>
                    <asp:TextBox ID="YourName" runat="server" Width="250px" />
                </td>
            </tr>
            <tr>
                <td>
                    Your age:
                </td>
                <td>
                    <asp:TextBox ID="YourAge" runat="server" Width="250px" />
                </td>
            </tr>
            <tr>
                <td>
                    Gender:
                </td>
                <td>
                    <asp:TextBox ID="txtGender" runat="server" Width="250px" />
                </td>
            </tr>
            <tr>
                <td>
                    Mobile:
                </td>
                <td>
                    <asp:TextBox ID="txtMobile" runat="server" />
                </td>
            </tr>

             <tr>
                <td>
                   EmailID
                </td>
                <td>
                    <asp:TextBox ID="txtEmailID" runat="server" />
                </td>
            </tr>

             <tr>
                <td>
                 Description:
                </td>
                <td>
                    <asp:TextBox ID="txtdescrition" runat="server" />
                </td>
            </tr>
            <tr>
            <td colspan="2">
            <asp:Button ID="Button1" runat="server" Text="Send" 
                    OnClick="Button1_Click" ValidationGroup="save" />
            </td>
            
            </tr>
            <tr>
            <td colspan="2"><asp:label id="DisplayMessage" runat="server" visible="false" xmlns:asp="#unknown" /></td>
            </tr>
        </table>

</div>



.aspx.cs page...:)
C#
protected void SendMail()
    {
        // Gmail Address from where you send the mail
        var fromAddress = "Your email address";
        // any address where the email will be sending
        var toAddress = txtEmailID.Text.ToString();
        //Password of your gmail address
        const string fromPassword = "Password";
        // Passing the values and make a email formate to display
        string subject = txtdescrition.Text.ToString();
        string body = "From: " + YourName.Text + "\n";
        body += "Email: " + txtEmailID.Text + "\n";
        body += "Subject: " + txtdescrition.Text + "\n";
        body += "Mobile: \n" + txtMobile.Text + "\n";
        // smtp settings
        var smtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
            smtp.Timeout = 20000;
        }
        // Passing values to smtp object
        smtp.Send(fromAddress, toAddress, subject, body);
    }

    protected void Button1_Click(object sender, EventArgs e)

   {
        SendMail();
        try
        {
            //here on button click what will done 
            SendMail();
            DisplayMessage.Text = "Your Comments after sending the mail";
            DisplayMessage.Visible = true;
            YourSubject.Text = "";
            txtEmail.Text = "";
            YourName.Text = "";
            Comments.Text = "";
        }
        catch (Exception) { }
    }
 
Share this answer
 
v3
Comments
NayakMamuni 5-Jul-13 3:11am    
Sir,

Please do as per my requirement.
NayakMamuni 9-Aug-13 8:45am    
Dear Nirav,

I want to fix the credentials of gmail from the mail has to be send and also want to fix the mail id to which the mail has to be send. I have tried to fix both the mail ids but fail to send. Please give me solution.
Nirav Prabtani 5-Jul-13 4:04am    
Try my above updated solution...:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900