ForestTech 0 Light Poster

Hi All,

I'm creating a helpdesk style feedback form that saves to an xml file so that we can track past requests. The XML part works fine, but the problem I'm having is getting the form to email off details to alert us when a new request is made. The form appears to be working (in that I'm not getting any error message, but the emails aren't coming through.

The form code is:

<table cellpadding="3" cellspacing="3" align="center">  
    <tr>
        <td bgcolor="#F0F0F0" colspan="2" align="center">
            <font face="Arial, Helvetica, sans-serif" size="2"><b>Please Fill Out The Form Below</b></font>
        </td>
    </tr>
    <tr>
        <td>
            <font face="Arial, Helvetica, sans-serif" size="2">Name:*</font>
        </td>
        <td>
             <ASP:Textbox id="name" size="64" runat="server"/>
        </td>
        <td>
            <asp:RequiredFieldValidator id="nameRequired" runat="server" ControlToValidate="name"
                ErrorMessage="You must enter a value into Name" Display="dynamic">Enter name
            </asp:RequiredFieldValidator>            
              </td>
    </tr>
    <tr>
        <td>
            <font face="Arial, Helvetica, sans-serif" size="2">Company:*</font>
        </td>
        <td>
             <ASP:Textbox id="company" size="64" runat="server" />
        </td>
        <td>
            <asp:RequiredFieldValidator id="companyRequired" runat="server" ControlToValidate="company"
                ErrorMessage="You must enter a value into Company" Display="dynamic">Enter company
            </asp:RequiredFieldValidator>            
              </td>
    </tr>
    <tr>
        <td>
            <font face="Arial, Helvetica, sans-serif" size="2">Phone(B/H):</font>
        </td>
        <td>
             <ASP:Textbox id="busphone" size="64" runat="server" />
        </td>
    </tr>
    <tr>
        <td>
            <font face="Arial, Helvetica, sans-serif" size="2">Phone(A/H):</font>
        </td>
        <td>
             <ASP:Textbox id="ahphone" size="64" runat="server" />
        </td>
    </tr>
    <tr>
        <td>
            <font face="Arial, Helvetica, sans-serif" size="2">Mobile:</font>
        </td>
        <td>
             <ASP:Textbox id="mobile" size="64" runat="server" />
        </td>
    </tr>
    <tr>
        <td>
            <font face="Arial, Helvetica, sans-serif" size="2">Email:</font>
        </td>
        <td>
             <ASP:Textbox id="txtEmail" size="64" runat="server" />
        </td>
    </tr>

    <tr>
        <td>
            <font face="Arial, Helvetica, sans-serif" size="2">Comment:*</font>
        </td>
        <td>
             <ASP:Textbox id="comment" TextMode="Multiline" columns="50" rows="10" wrap="true" runat="server" />
        </td>
        <td>
        <asp:RequiredFieldValidator id="commentRequired" runat="server" ControlToValidate="comment"
                ErrorMessage="You must enter a value into textbox1" Display="dynamic">Enter comment
            </asp:RequiredFieldValidator>            
              </td>
    </tr>
    <tr>
        <td colspan="2" bgcolor="#F0F0F0" colspan="2" align="center">
            <ASP:Button id="submit" runat="server" Text="Submit" OnClick="Save_Comment"/>
        </td>
    </tr>
</table>

and the C# code behind code is:

public partial class _Default : System.Web.UI.Page
{
    public TextBox comment;
    public TextBox txtEmail;

    protected void Save_Comment(object sender, EventArgs e)
    {
        try
        {

            MailMessage message = new MailMessage(txtEmail.Text, "helpdesk@mailserver.com", "Helpdesk Request", comment.Text);
            SmtpClient txtEmailClient = new SmtpClient("ns1.mailserver.com");
            System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("helpdesk@mailserver.com", "password");
            txtEmailClient.UseDefaultCredentials = false;
            txtEmailClient.Credentials = SMTPUserInfo;
            txtEmailClient.Send(message);

        }
        catch (Exception ex)
        {
        }
    }
}

Forgive the lack of naming conventions! I realised AFTER I hacked apart an old html form from my early web days.

NB. It may or may not also be worth noting that the web server and the mail server are the same.

I had a basic test script that worked, yet this one won't, so any ideas would be great!!

Thanks in advance.
Luke
ForestTech

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.