Help with SMTP
Glenn Kidd
gek8365 at garnet.acns.fsu.edu
Wed Nov 24 13:33:29 EST 1999
Hello,
I wrote a few weeks ago and I received a lot of responses. I have a new
problem. I am trying to write a form mailer and I have gotten the script to
accept the form data and mail the info. The message is received and
everyhting looks in order but the website reports a "500 Internal Server
Error". When I look at the server log I get the following description of
the error:
[Wed Nov 24 13:23:30 1999] [error] [client 128.186.86.106] Premature end of
script headers: /home/httpd/cgi-bin/mail.py
I will include the script. Any help would be greatly appreciated (and duely
noted in the header of the script)
#!/usr/bin/python
import cgi, smtplib, rfc822
form = cgi.FieldStorage() # get the form data
list = form.keys() # get the keys for the dictionary
form_dict = {} # initialize the form dictionary to NONE
def data2dict(new_dict, cgi_form_data, list_of_keys):
for cntr in range(len(list_of_keys)):
new_dict[list_of_keys[cntr]] =
cgi_form_data[list_of_keys[cntr]$
def sndmsg(dict):
input = open(dict['template'], 'r')
msg_body = input.read()
msg = msg_body % dict
toaddr = dict['send_to']
fromaddr = dict['email']
server = smtplib.SMTP('localhost')
server.sendmail(toaddr, fromaddr, msg)
server.quit()
data2dict(form_dict, form, list) # translate CGI data to a dictionary
sndmsg(form_dict)
More information about the Python-list
mailing list