Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i'm trying to send data from contact_us (html) form like name,email,phone,city and message to admin through email.

What I have tried:

my html pade code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Contact_Us Form</title>
    <link href="StyleSheetcontactus.css" rel="stylesheet" />
</head>
<body>
    <div class="contact-title">
        <h1>Contact Us</h1>
    </div>
    <div class="contact-form">
        <form id ="contact-form" method="post" action="">
            <input name="name" type="text" class="form-control" placeholder="Enter Name" required="" /><br />
            <input name="contact No." type="text" class="form-control" placeholder="Enter Contact no." required="" /><br />
            <input name="email" type="email" class="form-control" placeholder="Enter Email" required="" /><br />
            <input name="city" type="text" class="form-control" placeholder="Enter City" required="" /><br />
            <textarea name="message" class="form-control" placeholder="Enter Message" rows="5" required=""></textarea><br />
            <input type="submit" class="form-control submit" value="Send Message" />

        </form>
    </div>
</body>
</html>


below code is c# code but i don't know how can i send data through html
 WebClient client = new WebClient();

            string url = "http://manage.staticking.net/index.php/smsapi/httpapi/?uname=smarthitech&password=internet111&sender=WIFIND&receiver=" + mobile + "&route=TA&msgtype=1&sms=Dear User your OTP For signup to WIF India Fashion Pvt. Ltd. is " + phoneotp + " with the confirmation of your phone No. please keep it secure";


            try
            {
                Stream data = client.OpenRead(url);
                StreamReader reader = new StreamReader(data);
                string s = reader.ReadToEnd();
                data.Close();
                reader.Close();
            }
            catch (Exception ex)
            {
                Message.Show(ex.Message);
            }

//main code to send email
            MailMessage email1 = new MailMessage();
            email1.From = new MailAddress("wifindia123@gmail.com");
            email1.To.Add(email);
            email1.Subject = "Your Wifindia OTP:";
            email1.Body = "Dear User your OTP For signup to WIF India Fashion Pvt. Ltd. is " + emailotp + " with the confirmation of your Email ID please keep it secure";
            email1.BodyEncoding = System.Text.Encoding.UTF8;
            email1.IsBodyHtml = true;
            SmtpClient smtpc = new SmtpClient("smtp.gmail.com", 587);
            smtpc.EnableSsl = true;
            String UserId = "wifindia123@gmail.com";
            String Pass = "wifindiafashion@";
            smtpc.UseDefaultCredentials = false;
            smtpc.Credentials = new NetworkCredential(UserId, Pass);
            smtpc.Send(email1);
            Message.Show("Otp has sent to your Email(Inbox or spam) and Mobile ");
Posted
Comments
F-ES Sitecore 5-May-20 9:44am    
What's wrong with the code you have? Note that "it doesn't work" is not an answer that lets anyone help you.
Member 14743579 5-May-20 9:46am    
c# code is running but i don't have an idea how can i connect html page with c# page
F-ES Sitecore 5-May-20 9:49am    
You read form fields by

Request.Form["XYZ"]

where XYZ is the "name" attribute of the field you are trying to read.
MadMyche 5-May-20 10:04am    
1. Does this script work as it is?
2. If so, how do you want to alert the "admin"? Email, SMS, or something else?
DerekT-P 7-May-20 8:48am    
You put "ASP.Net" in the keywords, but there's no indication here you're using ASP.Net. You've posted some static HTML and some (non-web-related) C# code. I guess you've cut/pasted the mail code (SMTP etc) from somewhere else?
You need to take a (large) step back and learn ASP.Net. It's not appropriate for us to teach you the whole ASP.Net paradigm in the answer to a question. What is "mobile" and what's in it? Why are you opening that page in WebClient? Why are you reading the response and discarding it? What's Message and what does .Show do?? These are all the hints to me that you need to go back to basics and start by learning what ASP.Net is and how it works. I do wish you well, we've all started somewhere!

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