468,740 Members | 1,864 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,740 developers. It's quick & easy.

Email HTML form results via ASPX

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

Mar 2 '07 #1
2 1817
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>
Mar 2 '07 #2
On 2 Mar, 12:17, "Aidy" <a...@noemail.xxxa.comwrote:
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 = "fo*@hotmail.com";
newmail.From = "ma********@foo.com";

//If you want to CC this email to someone else
//objMM.Cc = "fo**@hotmail.com"

//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



Mar 2 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Nathaniel Maier | last post: by
1 post views Thread by Patrick | last post: by
7 posts views Thread by Martin | last post: by
2 posts views Thread by John Olsen | last post: by
4 posts views Thread by danxavier | last post: by
3 posts views Thread by Sam | last post: by
7 posts views Thread by thersitz | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.