Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
source code:
XML
<form id="contact-form"<%-- action="http://inthe7heaven.com/homeshop-html/php/contact.php"--%>>

    <label>Name(required)</label>
    <%--<input name="contact-name" type="text">--%>
    <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
    <label>Email(required)</label>
    <%--<input name="contact-email" type="text">--%>
    <asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
    <label>Subject</label>
    <%--<input name="contact-subject" type="text">--%>
    <asp:TextBox ID="txtsubject" runat="server"></asp:TextBox>
    <label>Message</label>
    <%--<textarea name="contact-message"></textarea>--%>
    <asp:TextBox ID="txtmessage" runat="server"></asp:TextBox>
    <%--<input class="big" type="submit" value="Send Message">--%>
    <asp:Button ID="btnsubmit" runat="server" Text="SUBMIT"
        CausesValidation="false" onclick="btnsubmit_Click1" />
   <%-- <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>--%>

</form>

C#
protected void btnsubmit_Click1(object sender, EventArgs e)
{
    MailMessage message = new MailMessage();
    message.From = new MailAddress("EmailRemoved@gmail.com");
    message.To.Add(new MailAddress(txtemail.Text.ToString()));
    message.Subject = txtsubject.Text;
    message.IsBodyHtml = true;
    message.Body = txtmessage.Text.Trim();

    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.EnableSsl = true;
    NetworkCredential NetworkCred = new NetworkCredential("EmailRemoved@gmail.com", "PasswordRemoved");
    smtp.UseDefaultCredentials = true;
    smtp.Credentials = NetworkCred;
    smtp.Port = 587;
    smtp.Send(message);
    ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}



[Edit member="Tadit"]
Corrected formatting and grammatical issues.
Added pre tags.
Email and Password Removed.
[/Edit]
Posted
v3
Comments
Did you set the debugger inside the event and test?

Hi Naramadhu

Try the below steps and run your application:

1.Add runat="server" in form tag.
2.Remove the action "<%-- action="http://inthe7heaven.com/homeshop-html/php/contact.php"--%>" from the form tag.
3.If you want to redirect to "Contact.php" page after sending the mail, write response.redirect("../contact.php") at the end of btnSubmit click fuction.

Hope this will work.
 
Share this answer
 
Try fixing the action on your form tag
<form id="contact-form"<%-- action="http://inthe7heaven.com/homeshop-html/php/contact.php"--%>>

to
<form runat="server" id="frmDefault">


I don't think it matters much what you name or set the ID of the form tag to unless you want to alter the form in code behind.
 
Share this answer
 

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