-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact.aspx.cs
More file actions
127 lines (117 loc) · 6.81 KB
/
contact.aspx.cs
File metadata and controls
127 lines (117 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Net;
using System.Net.Mail;
using System.Security.Cryptography;
public partial class contact : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["reg"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand checkemail = new SqlCommand("Select * from signup where Email='" + t2.Text.Trim() + "'", con);
SqlDataReader read = checkemail.ExecuteReader();
if (read.HasRows)
{
con.Close();
con.Open();
string insertCmd = "insert into contact(Name,Email,Topic,Message)values(@Name,@Email,@Topic,@Message)";
SqlCommand insertuser = new SqlCommand(insertCmd, con);
insertuser.Parameters.AddWithValue("@Name", t1.Text);
insertuser.Parameters.AddWithValue("@Email", t2.Text.Trim().ToLower());
insertuser.Parameters.AddWithValue("@Topic", t3.Text);
insertuser.Parameters.AddWithValue("@Message", t4.Text);
insertuser.Parameters.AddWithValue("@timepunch", DateTime.Now);
try
{
insertuser.ExecuteNonQuery();
con.Close();
try
{
MailMessage mail = new MailMessage();
mail.To.Add(t2.Text.Trim());
mail.From = new MailAddress("computercomrade37@gmail.com");
mail.Subject = "Thankyou for Contacting with us. Our team will contact you ASAP";
string emailBody = "";
emailBody += "<div style='background:#FFFFFF; font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px; margin:0; padding:0;'>";
emailBody += "<table cellspacing='0' cellpadding='0' border='0' width='100%' style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;'>";
emailBody += "<tbody>";
emailBody += "<tr>";
emailBody += "<td valign='top' style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;'>";
emailBody += "<div style='width:600px;margin-left:auto;margin-right:auto;clear:both;'>";
emailBody += "<div style='float:left;width:600px;min-height:35px;font-size:26px;font-weight:bold;text-align:left'>";
emailBody += "<div style='clear:both;width:100%;text-align:center;'> Knack Tutorials</div>";
emailBody += "<div style='clear:both;width:100%;text-align:center;font-size:11px;font-style:italic;'> Way To Success</div>";
emailBody += "</div>";
emailBody += "</div>";
emailBody += "</td>";
emailBody += "</tr>";
emailBody += "</tbody>";
emailBody += "</table>";
emailBody += "<table cellspacing='0' cellpadding='0' border='0' width='600' style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;margin-left:auto;margin-right:auto;'>";
emailBody += "<tbody>";
emailBody += "<tr>";
emailBody += "<td valign='top' colspan='2' style='width:600px;padding-left:20px;padding-right:20px;font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;'>";
emailBody += "<p style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;padding-top:15px;line-height:22px;margin:0px;font-weight:bold;padding-bottom:5px'>Hi " + t1.Text + ",</p>";
emailBody += "<p style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;line-height:22px;color:rgb(41,41,41)'>Email: " + t2.Text + "</p>";
emailBody += "<p style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;line-height:22px;color:rgb(41,41,41)'>Thanks for reaching us.. We ll contact you ASAP.</p>";
emailBody += "<p> </p><p style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;line-height:22px;margin:0px'>If you have any additional queries, please feel free to reach out us at +91 XXXXX XXXXX or drop us an email at <a href='mailto:Websiteweb.com' style='text-decoration:none;font-style:normal;font-variant:normal;font-weight:normal;font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;line-height:normal;color:rgb(162,49,35)' target='_blank'>example@domain.com</a>. We are here to help you.</p>";
emailBody += "<p> </p>";
emailBody += "<p style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;line-height:22px;margin:0px;font-weight:bold'>Best Regards,</p>";
emailBody += "<p style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;color:rgb(41,41,41);line-height:22px;margin:0px'>Knack Tutorials</p>";
emailBody += "</td>";
emailBody += "</tr>";
emailBody += "</tbody>";
emailBody += "</table>";
emailBody += "</div>";
mail.Body = emailBody;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential("computercomrade37@gmail.com", "9973142196aA@#");
smtp.Send(mail);
}
catch (Exception ex)
{
throw ex;
// msg = ex.Message;
}
Label3.Text = "You Contact us successfully. Our team will Contact you ASAP";
Label3.ForeColor = System.Drawing.Color.Green;
//Response.Redirect("SignUp.aspx");
}
catch (Exception er)
{
Label3.Text = "something going wrong." + er;
Label3.ForeColor = System.Drawing.Color.Red;
}
finally
{
}
}
else
{
Label3.Text = "Your email is already exists. Please try with different email or login to your account";
Label3.ForeColor = System.Drawing.Color.Red;
con.Close();
}
}
}