How to use python or mod_python file to handle HTML form?

Discussion in 'Python' started by Nancy, Jul 28, 2004.

  1. Nancy

    Nancy Guest

    Hi, Guys,
    I am new to Python. I am trying to following the example on
    http://www.modpython.org/live/current/doc-html/tut-pub.html
    In this example, it gives the following html code,
    <form action="form.py/email" method="POST">
    Name: <input type="text" name="name"><br>
    Email: <input type="text" name="email"><br>
    Comment: <textarea name="comment" rows=4 cols=20></textarea><br>
    <input type="submit">
    </form>
    ===============
    And form.py:
    ==============
    import smtplib
    WEBMASTER = "webmaster" # webmaster e-mail
    SMTP_SERVER = "localhost" # your SMTP server
    def email(req, name, email, comment):
    if not (name and email and comment):
    return "A required parameter is missing, \
    please go back and correct the error"
    msg = """\
    From: %s
    Subject: feedback
    To: %s
    I have the following comment:
    %s
    Thank You,
    %s
    """ % (email, WEBMASTER, comment, name)
    conn = smtplib.SMTP(SMTP_SERVER)
    conn.sendmail(email, [WEBMASTER], msg)
    conn.quit()
    # provide feedback to the user
    s = """\
    <html>
    Dear %s,<br>
    Thank You for your kind comments, we
    will get back to you shortly.
    </html>""" % name
    return s
    =====================
    My environment is
    1) Apache 2.0 server runs on WinXP Pro using 8080 port (IIS runs at
    same time on 80 port)
    2) I don't have any permission to access any SMTP server.
    3) I don't want to install any SMTP server on my PC.
    Now the question is,
    I cann't run above example code since I don't have SMTP server on my
    PC. How can I use my form.py to handle HTML form?

    Thanks a lot.

    Nancy
    Nancy, Jul 28, 2004
    #1
    1. Advertising

  2. On 27 Jul 2004, Nancy wrote:

    > I cann't run above example code since I don't have SMTP server on my
    > PC. How can I use my form.py to handle HTML form?


    Your ISP should provide an SMTP server you can use: for me, it's
    smtp.charter.net (being a Charter subscriber); it should be something
    similar for yours. If your ISP doesn't provide SMTP, you can probably
    find an open SMTP relay on the Internet somewhere, though I wouldn't
    really recommend that if you can avoid it. Setting SMTP_SERVER to this
    server and WEBMASTER to whichever e-mail address to which you want the
    e-mail to be sent should be all you need.
    Christopher T King, Jul 28, 2004
    #2
    1. Advertising

  3. Nancy

    Byron Guest

    Hi Nancy,

    Please answer the following questions:

    1) Do you have access to a web server? [yes / no]
    2) Do you have access to a SMTP server? [yes / no]

    If you answered "no" to any of the following questions above, this code
    sample will not work for you. Why?

    1) You must have access to a web server in order for the form to be
    processed.
    2) You must have access to an SMTP server in order to send e-mail on the
    Internet. Without this, you are toast.

    Byron
    ---

    Nancy wrote:

    > Hi, Guys,
    > I am new to Python. I am trying to following the example on
    > http://www.modpython.org/live/current/doc-html/tut-pub.html
    > In this example, it gives the following html code,
    > <form action="form.py/email" method="POST">
    > Name: <input type="text" name="name"><br>
    > Email: <input type="text" name="email"><br>
    > Comment: <textarea name="comment" rows=4 cols=20></textarea><br>
    > <input type="submit">
    > </form>
    > ===============
    > And form.py:
    > ==============
    > import smtplib
    > WEBMASTER = "webmaster" # webmaster e-mail
    > SMTP_SERVER = "localhost" # your SMTP server
    > def email(req, name, email, comment):
    > if not (name and email and comment):
    > return "A required parameter is missing, \
    > please go back and correct the error"
    > msg = """\
    > From: %s
    > Subject: feedback
    > To: %s
    > I have the following comment:
    > %s
    > Thank You,
    > %s
    > """ % (email, WEBMASTER, comment, name)
    > conn = smtplib.SMTP(SMTP_SERVER)
    > conn.sendmail(email, [WEBMASTER], msg)
    > conn.quit()
    > # provide feedback to the user
    > s = """\
    > <html>
    > Dear %s,<br>
    > Thank You for your kind comments, we
    > will get back to you shortly.
    > </html>""" % name
    > return s
    > =====================
    > My environment is
    > 1) Apache 2.0 server runs on WinXP Pro using 8080 port (IIS runs at
    > same time on 80 port)
    > 2) I don't have any permission to access any SMTP server.
    > 3) I don't want to install any SMTP server on my PC.
    > Now the question is,
    > I cann't run above example code since I don't have SMTP server on my
    > PC. How can I use my form.py to handle HTML form?
    >
    > Thanks a lot.
    >
    > Nancy
    Byron, Jul 28, 2004
    #3
  4. Nancy

    Nancy Guest

    > 1) Do you have access to a web server? [yes / no]
    > 2) Do you have access to a SMTP server? [yes / no]


    For question 1, is YES, for question 2 is NO.

    I know I cann't following this example. My question is if I don't
    use SMTP server, is there any other way to handle HTML form? for
    example php, ASP, java Applet can do it very well (by using some
    functions or variables).

    Thanks.

    Nancy
    Nancy, Jul 29, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dietrich
    Replies:
    1
    Views:
    641
    Joe Smith
    Jul 22, 2004
  2. Leon
    Replies:
    2
    Views:
    524
  3. =?ISO-8859-1?Q?KLEIN_St=E9phane?=
    Replies:
    3
    Views:
    446
    hanumizzle
    Oct 6, 2006
  4. blbmdsmith
    Replies:
    1
    Views:
    643
    Graham Dumpleton
    Dec 14, 2006
  5. Ludwigi Beethoven

    How do I handle an HTML form from ruby?

    Ludwigi Beethoven, Aug 20, 2003, in forum: Ruby
    Replies:
    2
    Views:
    136
    Pit Capitain
    Aug 21, 2003
Loading...

Share This Page