How can I add more fields to get emailed in this script, Is there a way I can just loop through all the fields I can do it asp classic . I tried adding another mail.body but it only sends 1 mail.body

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.IO" %>

<script language = "javascript">
	function Tocheck(frmemail)  {
		if(frmemail.txtFile.value  == "")  {
		alert("Please attach a file");

<script runat="server">

void btnSubmit_Click(Object sender, EventArgs e) {

MailMessage mail = new MailMessage();
mail.From = txtFrom.Text;
mail.To = txtTo.Text;
mail.Subject = txtSubject.Text;
mail.Body = txtMsg.Text;
mail.BodyFormat = MailFormat.Html;

string strdir = "D:\\temp\\";

string strfilename = Path.GetFileName(txtFile.PostedFile.FileName);


mail.Attachments.Add(new MailAttachment(strdir+strfilename));

catch(Exception ex)
Response.Write("<b>Exception Occured:</b>   " +ex);
Response.Write("Your E-mail has been sent sucessfully");

// Uploaded file deleted after sending e-mail




<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Using ASP.NET To Send Email - Part 2</title>


<div align="center">
<form method = "post" name = "frmemail" runat = "server" enctype="multipart/form-data" onSubmit = "return Tocheck(this)">
	<table border="1" width="637" height="196">
			<td height="196" width="637" valign="top">
			From : <asp:TextBox ID = "txtFrom" Runat =server></asp:TextBox>
			<p>To: <asp:TextBox ID = "txtTo" Runat = server></asp:TextBox>
			<p>Subject:<asp:TextBox ID = "txtSubject" Runat = server></asp:TextBox>

			<p>Message:<asp:TextBox runat="server" Height="57px" TextMode="MultiLine" Width="212px" ID="txtMsg"></asp:TextBox>

			<p>Attach:<input type = "file" id = "txtFile" runat = "server">

			<p align="center"><asp:Button Runat = server ID = "btnSubmit" Text = "SEND" OnClick = "btnSubmit_Click"></asp:Button></td>



I can not understand your requirement. Are talking about mass email? or want to add more data in a single mail body?

I want to add more textbox's that get sent with the form. firstname, lastname, address etc.

This article has been dead for over six months. Start a new discussion instead.