Click here to Skip to main content
15,922,407 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, could someone please help me, I would like to know the code for the submit button in c# so when someone presses the button it sends a email to my email address
Posted

"Code for button"? I don't think you need exactly, this, but people should get answers their questions deserve.
HTML
<form ...>
    <input type="submit" value="Submit">
</form>

Please see: http://www.w3schools.com/Tags/att_input_type.asp[^].

If you do it this way, all data in the form (per attributes name and their values) will be automatically put to a single HTTP request and sent to the server side. This is how the Web form work. This is your responsibility to process form data on the server side.

As to e-mails, be extra careful. This is a very vulnerable points. One wrong move, and your server host will be turned into a zombie sending spam, or something like that, in no time. Injection of malicious code in form data is just a kid's play. Don't even play with the idea of sending any data as is. To avoid the exploit, please see my past answer:
unable to send mail , it showing the error in below code .[^].

—SA
 
Share this answer
 
why do you need to use submit button if there is an asp button?
try this

C#
<asp:button id="button" runat="server" onclick="click" cssclass="contact" xmlns:asp="#unknown">
//If you don't want to use the asp:button

<button id="button" runat="server" OnServerClick="click" >
</asp:button>


in code behind

C#
protected void click(object sender, EventArgs e)
{
    //do send email
}
 
Share this answer
 
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Feb-14 19:45pm    
Frankly, this is a pretty bad article. In addition to its low quality, this is a direct invitation for easy exploit of the site using such a naive approach.
Please see my answer.
—SA
[no name] 17-Feb-14 19:57pm    
Frankly I don't know who you are but you are doing my head in,
Sergey Alexandrovich Kryukov 17-Feb-14 20:23pm    
Excuse me?... "...in,..."? what? Did you read my answer? Who is who is really irrelevant...
—SA

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