Email HTML form results via ASPX

S

stew dean

Hi,

I'm a newbie so go easy. I'm having to covert an old site I've done
to run in a .net environment and have limited time to do this.

What I've learnt so far is the ideal way to do this is to recreate the
form as an aspx page and let the page handle it's own output. This I
will do later for a feedback form. But for now I have the rest of
the site that has a form to submit an email address to sign up for a
mailing list. I can't change all these .html pages to .aspx for
multiple reasons (and can't reconfigure the server).

Where can I find a script or learn about how to put together a script
that will accept output from a HTML page, email it to me via aspx and
then forward me to another HTML page?

Cheers

Stewart Dean
 
A

Aidy

page1.htm

<body>
<form action="test.aspx" method="get">
Email: <input type="text" name="txtEmail">
<br>
<input type="submit" value="Submit">
</form>
</body>

test.aspx

private void Page_Load(object sender, System.EventArgs e)
{
// read the email field from the form
string email = Request.QueryString["txtEmail"];

// insert code here to do what you need to do with the address

// Send the user to page2.htm
Response.Redirect ("page2.htm");
}

page2.htm

<body>

<p>Thank you for subscribing.</p>

</body>
 
S

stew dean

page1.htm

<body>
<formaction="test.aspx" method="get">
Email: <input type="text" name="txtEmail">
<br>
<input type="submit" value="Submit">
</form>
</body>

test.aspx

private void Page_Load(object sender, System.EventArgs e)
{
// read theemailfield from theform
stringemail= Request.QueryString["txtEmail"];

// insert code here to do what you need to do with the address

// Send the user to page2.htm
Response.Redirect ("page2.htm");
}

page2.htm

<body>

<p>Thank you for subscribing.</p>

</body>


Thanks for that, had to work out a few things, firstly this is C# (my
send mail portion was in VB) - looking at C# it's better and more
familiar. Once I worked this out here's the script I came up with
(names changed to protect the innocent).


<% @Import Namespace="System.Web.Mail" %>
<script language="c#" runat="server">

private void Page_Load(object sender, System.EventArgs E)
{
// read the email field from the form
string addemail = Request.QueryString["txtEmail"];

//Create an instance of the MailMessage class
MailMessage newmail = new MailMessage();

newmail.To = "(e-mail address removed)";
newmail.From = "(e-mail address removed)";

//If you want to CC this email to someone else
//objMM.Cc = "(e-mail address removed)"

//email format. Can be Text or Html
newmail.BodyFormat = MailFormat.Text;

//Set the priority - options are High, Low, and Normal
newmail.Priority = MailPriority.Normal;

//Set the subject
newmail.Subject = "Foo mail signup";

//Set the body
newmail.Body = addemail;

//Smtp Server
SmtpMail.SmtpServer = "something.foo.de";

//Send the message
SmtpMail.Send(newmail);

Response.Redirect ("http://www.foo.com/thankyou.html");
}

</script>


Once I worked out // are comments and line ends are ; I recoded
the vb and nailed it.

The world is better again. Thanks for the help. Next stop - a multi
section form :).

Stew Dean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top