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

N

Nancy

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
 
C

Christopher T King

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.
 
B

Byron

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
 
N

Nancy

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
 

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,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top