Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,
i hava a contact us form that is working fine on my local host. but after uploading it to the hosting server it is not working . below is my code.
XML
<div style="width:300px; margin-left:30px; float:left; height:auto;">
<h1>Feedback Form</h1><hr />
 <fieldset>
<legend>Contact us</legend>


<div>
<%--<asp:Label ID="Name" runat="server" Text="Your Name*:"/><br/>--%>
<asp:TextBox ID="txtName" runat="server" placeholder="Your Name" CssClass="twitterStyleTextbox"  /><br />
<asp:RequiredFieldValidator ID="RV1" runat="server"
                            ControlToValidate="txtName"  ForeColor=Red
                            ErrorMessage="Please Enter Your Name"
                            SetFocusOnError="True">
</asp:RequiredFieldValidator><br />
</div>

<div>
<%--<asp:Label ID="Email" runat="server" Text="Email*:"/><br/>--%>
<asp:TextBox ID="txtMail" runat="server" placeholder="Your Email Id" CssClass="twitterStyleTextbox"/><br />
<asp:RequiredFieldValidator ID="RV2" runat="server"
                            ControlToValidate="txtMail" ForeColor=Red
                            ErrorMessage="Your Email Address"
                            SetFocusOnError="True">
</asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator1"
    runat="server" ErrorMessage="Please Enter valid Email Address"
    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
        ControlToValidate="txtMail" ForeColor="#FF3300"></asp:RegularExpressionValidator><br />
</div>

<div>
<%--<asp:Label ID="Sub" runat="server" Text="Subject*:"/><br/>--%>
<asp:TextBox ID="txtSubject" runat="server" placeholder="Subject" CssClass="twitterStyleTextbox"/><br />
<asp:RequiredFieldValidator ID="RV3" runat="server"
                            ControlToValidate="txtSubject" ForeColor=Red
                            ErrorMessage="Reason to contact us"
                            SetFocusOnError="True">
</asp:RequiredFieldValidator><br />
</div>

<div>
<%--<asp:Label ID="Message" runat="server" Text="Feedback:"/><br/>--%>
<asp:TextBox ID="txtMessage" runat="server" CssClass="twitterStyleTextbox"
        placeholder="Your Message" TextMode="MultiLine" Width="249px"/><br />
<asp:RequiredFieldValidator ID="RV4" runat="server"
                            ControlToValidate="txtMessage" ForeColor=Red
                            ErrorMessage="Please write your feedback"
                            SetFocusOnError="True">
</asp:RequiredFieldValidator><br />
</div>

<div>
<asp:Button  ID="btnSubmit" runat="server"
            Text="Submit" onclick="btnSubmit_Click"/>
</div>
<asp:ValidationSummary ID="ValidationSummary1"
                       runat="server"/>
</fieldset>
<asp:Label ID="Label1" runat="server" Text=""/>
</div>


my c# code
XML
private void sendmail()
   {
       try
       {

           str_mailer.Append(@"<b>Name : </b>  " + txtName.Text);
           str_mailer.Append(@"<br/> <b>Email Address : </b>" + txtMail.Text);
           str_mailer.Append(@"<br/><b>Subject : </b>" + txtSubject.Text);
           str_mailer.Append(@"<br/><b>Message : </b>" + txtMessage.Text);
           System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(ConfigurationManager.AppSettings["id"], ConfigurationManager.AppSettings["to"], "Contact Us", str_mailer.ToString());
           System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["id"], ConfigurationManager.AppSettings["pswd"]);
           System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["smtp"], Convert.ToInt32(ConfigurationManager.AppSettings["port"]));
           mailClient.EnableSsl = true;
           mail.IsBodyHtml = true;
           mailClient.UseDefaultCredentials = false;
           mailClient.Credentials = mailAuthentication;
           mailClient.Send(mail);
           Label1.Text = "<b>Thank you for contacting with us. We will be in contact with you soon.<b>";
       }
       catch
       {



           Label1.Text = "Please wait..";
           sendmail();


       }

   }

   protected void btnSubmit_Click(object sender, EventArgs e)
   {
       sendmail();
       txtMail.Text = "";
       txtMessage.Text = "";
       txtSubject.Text = "";
       txtName.Text = "";
   }


web.config code
XML
<appSettings>
  <add key="to" value="to address"/>
  <add key="from" value="mygmail@gmail.com "/>
  <add key="id" value="mygmail@gmail.com   "/>
  <add key="pswd" value="password"/>
  <add key="port" value="587"/>
  <add key="smtp" value="smtp.gmail.com"/>
</appSettings>





plz help someone to me.
Posted
Comments
JoCodes 13-Jan-14 23:10pm    
Any error message?
joginder-banger 13-Jan-14 23:20pm    
what's type of error you faced??
Member 10522141 14-Jan-14 1:13am    
its not showing any error. plz have a look
http://professional-tutors.org.uk/Contactus.aspx
Not working is not informative. Do you get any Exception?
Ron Beyer 13-Jan-14 23:49pm    
If he is, its a StackOverflowException, his exception handling code just calls itself again, and again, and again... He's swallowing everything else.

1 solution

Quote:

C#
catch
{
   Label1.Text = "Please wait..";
   sendmail();

   // Please Log the Exception
}
You are sending mail inside Catch Block. Is that what you need? Rather just log the Exception in some File or Database, so that you can track why exactly it is failing to work as expected.

There must be some problems while sending the mail and it might be due to many reasons.
Firewall/AntiVirus blocking the port 587 is a very common issue.

Refer my answer - sending email to gmail from asp.net[^] and check if you are doing it correctly.

Once you log the Exception, you will be able to know the issue specifically. Then you can just search that Exception in Google and try the solutions suggested.
 
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