Help with SMTP

Glenn Kidd gek8365 at
Wed Nov 24 19:33:29 CET 1999


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] Premature end of
script headers: /home/httpd/cgi-bin/

I will include the script.  Any help would be greatly appreciated (and duely
noted in the header of the script)


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]] =

def sndmsg(dict):
        input = open(dict['template'], 'r')
        msg_body =
        msg = msg_body % dict
        toaddr = dict['send_to']
        fromaddr = dict['email']
        server = smtplib.SMTP('localhost')
        server.sendmail(toaddr, fromaddr, msg)

data2dict(form_dict, form, list)   # translate CGI data to a dictionary


More information about the Python-list mailing list