Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8295917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:46:38+00:00 2026-06-08T14:46:38+00:00

So the main purpose of my program is to allow users to fill out

  • 0

So the main purpose of my program is to allow users to fill out a request form on my website. Once the web-form is filled out and the user presses submit I have made it so the program will send the information they filled out to my email.

The two major problems I am having are that one unless the user attaches an attachment the web-form will not send. This is bad because it is not required that they do so. So I need some sort of if statement saying that the program still should send with or without an attachment. As well I would like the date to be send in the email sent to myself. How do I make it so the date is sent to my email of the second the user hit the submit button.

I have added most of the code below.

Thanks

private string SendMessage(string strTo, string strFrom, string strSubject, string strMessage, string strAttachment, string strBCC)
{
    try
    {
        System.Net.Mail.MailMessage mailMsg;
        string strEmail = "";
        string strSmtpClient = ConfigurationManager.AppSettings["SmtpClient"];
        string[] arrEmailAddress = strTo.Split(';');
        for (int intCtr = 0; intCtr < arrEmailAddress.Length; intCtr++)
        {
            strEmail = "";
            if (arrEmailAddress[intCtr].ToString().Trim() != "")
            {
                strEmail = arrEmailAddress[intCtr].ToString().Trim();
                mailMsg = new MailMessage(strFrom, strEmail, strSubject, strMessage);
                mailMsg.IsBodyHtml = true;
                if (!strBCC.Trim().Equals(string.Empty))
                    mailMsg.Bcc.Add(strBCC);

                /*** Added mail attachment handling ***/    
                System.Net.Mail.Attachment attachment;
                attachment = new System.Net.Mail.Attachment(strAttachment);
                mailMsg.Attachments.Add(attachment);

                SmtpClient smtpClient = new SmtpClient(strSmtpClient);
                smtpClient.UseDefaultCredentials = true;
                smtpClient.Port = 25;

                smtpClient.Send(mailMsg);
                mailMsg.Dispose();
            }
        }
        return "Message sent to " + strTo + " at " + DateTime.Now.ToString() + ".";
    }
    catch (Exception objEx)
    {
        return objEx.Message.ToString();
    }
}

protected void Submit_Click1(object sender, EventArgs e)
{
    try
    {
        /*** Moved from SendMessage function ****/
        string strUpLoadDateTime = System.DateTime.Now.ToString("yyyyMMddHHmmss");
        string strFileName1 = string.Empty;
        if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0))
        {
            string strUploadFileName1 = File1.PostedFile.FileName;
            strFileName1 = strUpLoadDateTime + "." + Path.GetFileNameWithoutExtension(strUploadFileName1) + Path.GetExtension(strUploadFileName1);
            strFileName1 = strFileName1.Replace("'", "");
            string strSaveLocation = Server.MapPath("") + "\\" + strFileName1;
            File1.PostedFile.SaveAs(strSaveLocation);
            txtComments.Text = "The file has been uploaded";
        }

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.Text.StringBuilder sb = new System.Text.StringBuilder();

sb.Append("<table>");
sb.AppendFormat("<tr><td>Request Name:</td><td>{0}</td></tr>", txtBugName.Text.Trim());
sb.AppendFormat("<tr><td>Category:</td><td>{0}</td></tr>", ddlModule.SelectedValue);
sb.AppendFormat("<tr><td>Sub-Category:</td><td>{0}</td></tr>", ddlPage.SelectedValue);
sb.AppendFormat("<tr><td>Description:</td><td>{0}</td></tr>", txtComments.Text.Trim());
sb.AppendFormat("<tr><td>Email is:</td><td>{0}</td></tr>", txtemail.Text.Trim());
sb.Append("<table>");



        SendMessage(ConfigurationManager.AppSettings["EmailAddrTo"],
            ConfigurationManager.AppSettings["EmailAddrFrom"],
            txtBugName.Text.Trim(),
            strMessage, strSaveLocation, "");
    }
    catch
    {
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:46:44+00:00Added an answer on June 8, 2026 at 2:46 pm

    Cleaned up yr method a bit

        /// <summary>
        /// Sends the message.
        /// </summary>
        /// <param name="strTo">The STR to.</param>
        /// <param name="strFrom">The STR from.</param>
        /// <param name="strSubject">The STR subject.</param>
        /// <param name="strMessage">The STR message.</param>
        /// <param name="strAttachment">The STR attachment.</param>
        /// <param name="strBCC">The STR BCC.</param>
        /// <returns></returns>
        private string SendMessage(string strTo, string strFrom, string strSubject, string strMessage, string strAttachment, string strBCC)
        {
            try
            {
                string strEmail = string.Empty;
                string strSmtpClient = ConfigurationManager.AppSettings["SmtpClient"];
                string[] arrEmailAddress = strTo.Split(';');
    
                foreach (string emailAddress in arrEmailAddress)
                {
                    if (!string.IsNullOrEmpty(emailAddress.Trim()))
                    {
                        using (System.Net.Mail.MailMessage mailMsg = new MailMessage(strFrom, strEmail, strSubject, strMessage))
                        {
                            mailMsg.IsBodyHtml = true;
                            if (!string.IsNullOrEmpty(strBCC))
                                mailMsg.Bcc.Add(strBCC);
    
                            if (!string.IsNullOrEmpty(strAttachment))
                            {
                                System.Net.Mail.Attachment attachment;
                                attachment = new System.Net.Mail.Attachment(strAttachment);
                                mailMsg.Attachments.Add(attachment);
                            }
    
                            using (System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(strSmtpClient))
                            {
                                smtpClient.UseDefaultCredentials = true;
                                smtpClient.Port = 25;
                                smtpClient.Send(mailMsg);
                            }
                        }
                    }
                }
                return string.Format("Message sent to {0} at {1}.", strTo, DateTime.Now);
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an OCR program, written with C# (WinForms app). So it's main purpose
I am going to write a hybrid Web/Desktop app. The main purpose of the
I am building an user interface. My program will consist of 4 main parts:
The situation is my program's purpose is to update employee details. The user may
What is the main purpose of overloading operators in C++? In the code below,
what is the main purpose of a destructor? could you give any examples of
what is the purpose of automation testing? According to me the main purpose is
What are the 'costs' involved in calling an empty PHP function? The main purpose
I wrote a program which crawls website, processes html pages and stores results in
I'm creating a website as a small store for personal use, my main question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.