views:

49

answers:

5

Hey guys,

First of all, I am a php developer and most of .net is alien to me which is why I am posting here!

I just migrated over a site from one set of webhosting to another. The whole site is written in .net. None of the site is database driven so most of it works, except for the contact form. The output on the site simple states there was an error with "There has been an error - please try to submit the contact form again, if you continue to experience problems, please notify our webmaster." This is just a simple message it pops out of it gets to the "catch" part of the email function.

I went into web.config and changed the parameters:

    <emailaddresses>
        <add name="System" value="[email protected]"/>
        <add name="Contact" value="[email protected]"/>
        <add name="Info" value="[email protected]"/>
    </emailaddresses>
    <general>
        <add name="WebSiteDomain" value="hoyespharmacy.com"/>
    </general>

Then the .cs file for contact contains the mail function EmailFormData():

private void EmailFormData()
{
    try
    {
        StringBuilder body = new StringBuilder();
        body.Append("Name" + ": " + txtName.Text + "\n\r");
        body.Append("Phone" + ": " + txtPhone.Text + "\n\r");
        body.Append("Email" + ": " + txtEmail.Text + "\n\r");
        body.Append("Fax" + ": " + txtEmail.Text + "\n\r");
        body.Append("Subject" + ": " + ddlSubject.SelectedValue + "\n\r");
        body.Append("Message" + ": " + txtMessage.Text);

        MailMessage mail = new MailMessage();
        mail.IsBodyHtml = false;
        mail.To.Add(new MailAddress(Settings.GetEmailAddress("System")));
        mail.Subject = "Contact Us Form Submission";
        mail.From = new MailAddress(Settings.GetEmailAddress("System"), Settings.WebSiteDomain);
        mail.Body = body.ToString();

        SmtpClient smtpcl = new SmtpClient();

        smtpcl.Send(mail);
    }
    catch
    {
        Utilities.RedirectPermanently(Request.Url.AbsolutePath + "?messageSent=false");
    }
}

How do I see what the actual error is. I figure I can do something with the "catch" part of the function.. Any pointers?

Thanks!

A: 

Comment out Utilities.RedirectPermanently(Request.Url.AbsolutePath + "?messageSent=false"); and replace it with throw;

Raj Kaimal
+3  A: 

Change the catch to

catch(Exception ex)
{
   throw;
}

The ex variable will hold your exception information, so you can put a breakpoint there. It'd be easier to step through it, but you can just throw the error as well.

Brandon
A: 

What development environment are you using?

It's probably best to use Visual Studio (Express if you don't have the full version), and debug this code, hitting F11 to step through each statement until it breaks. Then you should have access to more information.

Albert
netbeans using ftp as remote source. i dont have any fancy .net studies for .net since i never work in it, just helping move this site.
Roeland
A: 

I would suggest logging in the long term (such as log4net). But for the sake of speed try changing your catch statement to look like:

catch(Exception e)

and then use the debugger in VS to explore the actual exception.

dball917
A: 

Place a breakpoint on the first line of the EmailFormData method and run the application in debug mode. You can then step through the code line by line.

matt