Page view counter

Simple email form?

Last post 01-14-2009 4:03 AM by homstation. 15 replies.

Sort Posts:

  • Simple email form?

    11-22-2006, 3:09 PM
    • Loading...
    • nick818
    • Joined on 11-22-2006, 8:07 PM
    • Posts 7
    • Points 35

    Hello..

    I was just trying to create a simple survey on a web page with 3 questions and 3 possible responses to each question in the form of radio buttons. I'm used to PHP, which seems to be more different than I expected. Can you help me figure out the asp script needed to simply send the three answers to an email address? Thank you so much!
     

  • Re: Simple email form?

    11-22-2006, 5:46 PM
    • Loading...
    • ShepherdWeb
    • Joined on 11-08-2006, 9:56 PM
    • Posts 75
    • Points 186
    Do you need help creating the actual form, or just with the email functionality?
    ★ ShepherdWeb
  • Re: Simple email form?

    11-22-2006, 5:56 PM
    • Loading...
    • CyJacK
    • Joined on 03-02-2006, 10:10 PM
    • Posts 7
    • Points 32

    <%

    @ Page Language="C#" %>

    <%

    @ Import Namespace="System.Web.Mail" %>

    <

    script runat="server">

    //lets declare some variables to put our answers

    string answer1, answer2, answer3;

     

    protected void submit_Click(object sender, EventArgs e)

    {

     

    answer1 = Request[

    "QAnswers1"];

    answer2 = Request[

    "QAnswers2"];

    answer3 = Request[

    "QAnswers3"];

     

    sendEmail();

    }

    private void sendEmail()

    {

    // To:

    string strTo = "myemail@mycompany.com";

    //From:

    string strFrom = "me@asp.net";

    //Subject

    string strSubject = "Here the Answers";

    //

    string message = "Q1 = " + answer1 + ", Q2 = " + answer2 + ", Q3 = " + answer3;

     

    SmtpMail.Send(strFrom, strTo, strSubject, "A real nice body text here");

    Response.Write(

    "Email Send!");

     

    }

     

    </

    script>

     

    <!

    DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <

    html xmlns="http://www.w3.org/1999/xhtml" >

    <

    head id="Head1" runat="server">

    <title>Survey</title>

    </

    head>

    <

    body>

    <form id="form1" runat="server">

    <div>question 1?</div>

    <div>

    <asp:RadioButtonList ID="QAnswers1" runat="server">

    <asp:ListItem>answer1</asp:ListItem>

    <asp:ListItem>answer2</asp:ListItem>

    <asp:ListItem>answer3</asp:ListItem>

    </asp:RadioButtonList>

    </div>

    <div>question 2?</div>

    <div>

    <asp:RadioButtonList ID="QAnswers2" runat="server">

    <asp:ListItem>answer1</asp:ListItem>

    <asp:ListItem>answer2</asp:ListItem>

    <asp:ListItem>answer3</asp:ListItem>

    </asp:RadioButtonList>

    </div>

    <div>question 3?</div>

    <div>

    <asp:RadioButtonList ID="QAnswers3" runat="server">

    <asp:ListItem>answer1</asp:ListItem>

    <asp:ListItem>answer2</asp:ListItem>

    <asp:ListItem>answer3</asp:ListItem>

    </asp:RadioButtonList><br />

    <asp:Button ID="submit" runat="server" Text="Send!" OnClick="submit_Click" /></div>

    </form>

    </

    body>

    </

    html>
    "All men have the stars," he answered,
    "but they are not the same things for different people."
  • Re: Simple email form?

    11-22-2006, 10:22 PM
    • Loading...
    • nick818
    • Joined on 11-22-2006, 8:07 PM
    • Posts 7
    • Points 35
    Awesome! That looks like exactly what I need. I'll try it out. Thanks a lot.
  • Re: Simple email form?

    11-23-2006, 2:50 PM
    • Loading...
    • nick818
    • Joined on 11-22-2006, 8:07 PM
    • Posts 7
    • Points 35

    It's not working. I get this error:

    Active Server Pages error 'ASP 0221'

    Invalid @ Command directive

    /survey.asp, line 2

    The specified 'Page Language="C#" ' option is unknown or invalid.

     

  • Re: Simple email form?

    11-23-2006, 9:42 PM
    • Loading...
    • nick818
    • Joined on 11-22-2006, 8:07 PM
    • Posts 7
    • Points 35
    I should probably add that the server only has ASP 1.0 I think. Does that make a difference with this?
  • Re: Simple email form?

    11-24-2006, 8:53 AM
    • Loading...
    • CyJacK
    • Joined on 03-02-2006, 10:10 PM
    • Posts 7
    • Points 32
    do you want an ASP.NET or ASP 3.0 script?
    "All men have the stars," he answered,
    "but they are not the same things for different people."
  • Re: Simple email form?

    11-24-2006, 9:15 AM
    • Loading...
    • orjiani
    • Joined on 11-19-2006, 12:10 PM
    • localhost:2730/the_boy_is_here.aspx
    • Posts 16
    • Points 40

    the source code he posted is for asp.net (pages with .aspx extension not for asp) and the language is actually c#. Except you plan on using that, you should edit you question.

     

  • Re: Simple email form?

    11-24-2006, 9:26 AM
    • Loading...
    • CyJacK
    • Joined on 03-02-2006, 10:10 PM
    • Posts 7
    • Points 32

    try this, it is asp:

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <%
    Option Explicit
    %>

    <%
    dim answer1, answer2, answer3
     
    '-- Request for the answers
    answer1 = Request.Form("QAnswers1")
    answer2 = Request.Form("QAnswers2")
    answer3 = Request.Form("QAnswers3")

    dim objMail
    Set objMail = CreateObject("CDONTS.NewMail")

    objMail.To = "survey@mysurvey.com"
    objMail.From = "asppage@mysurvey.com"
    objMail.Subject = "Answer my survey"
    ' 0 for HTML Format
    objMail.BodyFormat = "0"
    objMail.Body = "Q1 = " & answer1 & VBCrLf & "Q2 = " & answer2 & VBCrLf & "Q3 = " & answer3 & VBCrLf
     
    ObjMail.Send

    'cleaning
    Set ObjMail = Nothing

    Response.Write("email send")

    %>


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Survey asp 3.0</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <form id="form1" method="post">

    <div>question 1?</div>
    <p>
      <label><input type="radio" name="QAnswers1" value="Answer1-1">Answer1</label>
      <br>
      <label><input type="radio" name="QAnswers1" value="Answer1-2">Answer2</label>
      <br>
      <label><input type="radio" name="QAnswers1" value="Answer1-3">Answer3</label>
      <br>
    </p>

    <div>question 2?</div>

    <p>
      <label><input type="radio" name="QAnswers2" value="Answer2-1">Answer1</label>
      <br>
      <label><input type="radio" name="QAnswers2" value="Answer2-2">Answer2</label>
      <br>
      <label><input type="radio" name="QAnswers2" value="Answer2-3">Answer3</label>
      <br>
    </p>

    <div>question 3?</div>
    <p>
      <label><input type="radio" name="QAnswers3" value="Answer3-1">Answer1</label>
      <br>
      <label><input type="radio" name="QAnswers3" value="Answer3-2">Answer2</label>
      <br>
      <label><input type="radio" name="QAnswers3" value="Answer3-3">Answer3</label>
      <br>
    </p>
    <input type="submit" id="submit" value="Send it!">

    </form>
    </body>
    </html>

    "All men have the stars," he answered,
    "but they are not the same things for different people."
  • Re: Simple email form?

    11-24-2006, 9:34 PM
    • Loading...
    • nick818
    • Joined on 11-22-2006, 8:07 PM
    • Posts 7
    • Points 35

    Im pretty sure I only have ASP 1.0, not 3.0...I tried that last source and got this error...

    Microsoft VBScript runtime error '800a01ad'

    ActiveX component can't create object: 'CDONTS.NewMail'

    /surveytest.asp, line 15

     

  • Re: Simple email form?

    11-25-2006, 11:51 AM
    • Loading...
    • CyJacK
    • Joined on 03-02-2006, 10:10 PM
    • Posts 7
    • Points 32

    sustitute the code for this one (changing the old CDONT.NewMail by CDO.Message):

     

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <%
    Option Explicit
    %>

    <%
    dim answer1, answer2, answer3
     
    '-- Request for the answers
    answer1 = Request.Form("QAnswers1")
    answer2 = Request.Form("QAnswers2")
    answer3 = Request.Form("QAnswers3")

    dim objMail
    Set objMail = CreateObject("CDO.Message")

    objMail.To = "survey@mysurvey.com"
    objMail.From = "asppage@mysurvey.com"
    objMail.Subject = "Answer my survey"
    objMail.HTMLBody = "Q1 = " & answer1 & VBCrLf & "Q2 = " & answer2 & VBCrLf & "Q3 = " & answer3 & VBCrLf 
    objMail.Send

    'cleaning
    Set ObjMail = Nothing

    Response.Write("email send")

    %>

    "All men have the stars," he answered,
    "but they are not the same things for different people."
  • Re: Simple email form?

    11-27-2006, 12:59 PM
    • Loading...
    • nick818
    • Joined on 11-22-2006, 8:07 PM
    • Posts 7
    • Points 35
    Success! Thanks! That worked, but one last thing. How can I set a page to direct to after hitting submit?
  • Re: Simple email form?

    11-27-2006, 1:09 PM
    • Loading...
    • nick818
    • Joined on 11-22-2006, 8:07 PM
    • Posts 7
    • Points 35
    Nevermind... Just fixed it with some javascript. :)
  • Re: Simple email form?

    12-17-2006, 6:32 AM
    • Loading...
    • vandiermen
    • Joined on 11-14-2006, 1:21 AM
    • Posts 30
    • Points 52

    I used Visual Web Developer 2005 with your second code and got this error

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30807: 'Let' and 'Set' assignment statements are no longer supported.

    Source Error:

    Line 12: 
    Line 13: dim objMail
    Line 14: Set objMail = CreateObject("CDONTS.NewMail")
    Line 15: 
    Line 16:     objMail.To = "survey@abcpchelp.com"

    Source File: C:\Documents and Settings\admin\My Documents\Visual Studio 2005\WebSites\WebSite17\Default.aspx    Line: 14
  • Re: Simple email form?

    12-18-2006, 1:31 PM
    • Loading...
    • CyJacK
    • Joined on 03-02-2006, 10:10 PM
    • Posts 7
    • Points 32

    Take off the Set statement.

     objMail  = CreateObject("CDONTS.NewMail")

     

    "All men have the stars," he answered,
    "but they are not the same things for different people."
Page 1 of 2 (16 items) 1 2 Next >