How to use python or mod_python file to handle HTML form?
DesertLinux at netscape.net
Wed Jul 28 16:21:20 CEST 2004
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
2) You must have access to an SMTP server in order to send e-mail on the
Internet. Without this, you are toast.
> Hi, Guys,
> I am new to Python. I am trying to following the example on
> 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">
> 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:
> Thank You,
> """ % (email, WEBMASTER, comment, name)
> conn = smtplib.SMTP(SMTP_SERVER)
> conn.sendmail(email, [WEBMASTER], msg)
> # provide feedback to the user
> s = """\
> 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.
More information about the Python-list