[Tutor] Having trouble with a form mail script.

jason.brashear@amd.com jason.brashear@amd.com
Fri, 30 Jun 2000 09:25:05 -0500


Hello,
 My problem is that I am trying to edit a script that creates a html page
after the for has been filled out correctly.
What I want to do is put a meta refresh but when I ad that Line I get an
Internal server error.

Here is the part that works:

    # Print confirmation
    
    print "Content-type: text/html\n"
    
    print "<HTML>\n"
    print "<HEAD>\n"
    print "<TITLE>Submission successful</TITLE>"
    print "</HEAD>\n"
    print "<BODY>\n"
    print "<H1>Submission successful</H1>\n"
    print "<P>Your submission has been mailed to the site administrators."
    print "<P>Confirmation has been sent to your email address."
    print "</P>\n"
    print "<P>Thank you.</P>\n"
    print "</BODY>\n";
    print "</HTML>\n"

But the user has to hit his or her back button. 
this is what I want to do:

                
    # Print confirmation
    
    print "Content-type: text/html\n"
    
    print "<HTML>\n"
    print "<HEAD>\n"
    print "<TITLE>Submission successful</TITLE>"
    print "<meta http-equiv="refresh" content="3;URL=http://k86tech">"
    print "</HEAD>\n"
    print "<BODY>\n"
    print "<H1>Submission successful</H1>\n"
    print "<P>Your submission has been mailed to the site administrators."
    print "<P>Confirmation has been sent to your email address."
    print "</P>\n"
    print "<P>Thank you.</P>\n"
    print "</BODY>\n";
    print "</HTML>\n"

But that doesn't work!
So I then tried this:

                
    # Print confirmation
    
    print "Content-type: text/html\n"
    
    print "<HTML>\n"
    print "<HEAD>\n"
    print "<TITLE>Submission successful</TITLE>"
    print "<meta http-equiv="refresh" content="3;URL=http://k86tech">\n"
    print "</HEAD>\n"
    print "<BODY>\n"
    print "<H1>Submission successful</H1>\n"
    print "<P>Your submission has been mailed to the site administrators."
    print "<P>Confirmation has been sent to your email address."
    print "</P>\n"
    print "<P>Thank you.</P>\n"
    print "</BODY>\n";
    print "</HTML>\n"
That didn't work either..
Any Ideas? Can some one please help?

If you would like to see the whole script here it is:



#!/usr/bin/python

"""
1/8/00 - Modified the original code to clean-up the email
format. Cleared a bug in the output string concatenation.
Filters out Submit and REQUIRED fields.

A quick-and-dirty CGI form mailer. Requires Python 1.5.1.

$Id: formmail.py,v 1.2 1999/01/28 11:42:57 larsga Exp $
"""

OK=0
try:
    import cgi
    import StringIO
    import string
    import smtplib
    import sys  # Standard modules

    import email
    import LBBemail

    # Config

    mailserver="techdoc.amd.com"
    mailrecip="k86access@techdoc.amd.com"
#    mailrecip="barnettl@techdoc.amd.com"
    subject="K86TECH Access Request Form"
    subject2="Automatic confirmation of your K86TECH access request."

    # Setup

    # Create output control


    # Process results

    form=cgi.FieldStorage()

    # Check that required fields are present

    OE=0

    if form.has_key("REQUIRED"):
        missing=[]
        for field in string.split(form["REQUIRED"].value):
            if not form.has_key(field):
                missing.append(field)
        if form["Approvers_Email"].value == "Other: -->" :
                OE=1
                if not form.has_key("Other_Email"):
                        missing.append("Select or fill-in an email
address.")

        if form.has_key("Your_Email") :
                 A3 =form["Your_Email"].value
                 youremail = LBBemail.testemail(A3)


        if missing!=[]:
            print "Content-type: text/html\n"

 print "<HTML>\n"
            print "<HEAD>\n"
            print "<TITLE>Submission unsuccessful</TITLE>"
            print "</HEAD>\n"
            print "<BODY>\n"
            print "<H1>Submission unsuccessful</H1>\n"
            print "<P>The following fields were missing:</P>\n"
            print "<UL>"   
            for field in missing:
                print "  <LI>"+field
            print "</UL>"
            print "<P>Please try again.</P>"
            print "</BODY>\n";
            print "</HTML>\n"   
        
            OK=1
            sys.exit()
                
        
# Set up the email  
#
# This is code that will detect a mail recipient coded
# into the HTML form. It is disabled to prevent the
# unauthorized use of this script as a remailer.
#
#    if form.has_key("email"):
#       mailrecip=form["email"].value
#       OK = 1
#       LBBemail.testemail(mailrecip)
            
    
            
    if form.has_key("Approvers_Email"):
             sendor = form["Approvers_Email"].value
             if OE == 1 :
                  sendor = form["Other_Email"].value
            
    OK = 1
    A = LBBemail.testemail(sendor)
            
                
            
            
            
#
# Produce email. Check to see if form keys are used
# prior to attempting to check their value or an
# error will result.  
#   
    out=StringIO.StringIO()
    out.write("To: %s\n" % A)
    out.write("Reply-to: %s\n" % mailrecip)
    out.write("Subject: %s\n\n" % subject)
    out.write(form["Your_Name"].value)
    out.write(" has requested access to the K86Tech web site\n")
    out.write("and has routed this request to you for approval. If you
approve\n")
    out.write("this request, REPLY to this email, type APPROVED, then send,
\n")
    out.write("including the information below, to %s\n\n" % mailrecip)
    out.write("The information submitted is:\n\n")



#    if  form.has_key("Link")  :
#               local_link = `form["Link"].value`
#    local_comments = "(none)"
#               local_comments = `form["comments"].value`
    C1 = ""
    C = "Test"
    
#  Telephone
    R = (       
                "Name: " + `form["Your_Name"].value`  + "\n\n" +
                "Login: " + `form["Login"].value`  + "\n\n" +
                "Temporary Password: " + `form["Password"].value`  + "\n\n"
+
                
                "Telephone: " + `form["Telephone"].value`  + "\n\n" +
                "Email: " + youremail + "\n\n"
                )
    if  form.has_key("Comments")  :
                C1 = "Comments:\n" + form["Comments"].value + "\n\n"
    C = R + C1
    
    D = string.replace(C, "'", "")
    out.write(D)
    out.write("\n\nConfirmation was mailed to " + youremail)
    
    
    
    
    
            
#
# This is old code that scanned all form fields and printed the values.
# It was replaced by the field-specific code, above.
#               
#               out.write("\n\n====================================\n")
#               out.write("\n\nThis is a complete listing of all raw
data:\n\n")
#  for fieldname in form.keys():
#       if fieldname != "REQUIRED" and fieldname != "submit" and fieldname
!= "":
#               out.write("---"+ fieldname +": \n")
#               B = form[fieldname].value
#               out.write( B + "\n\n")
                
    # Send email
    mail=smtplib.SMTP(mailserver)
#    mail.sendmail(mailrecip,[mailrecip],out.getvalue())
    mail.sendmail(A,[A],out.getvalue())
                
    # Print confirmation
    
    print "Content-type: text/html\n"
    
    print "<HTML>\n"
    print "<HEAD>\n"
    print "<TITLE>Submission successful</TITLE>"
    print "<meta http-equiv="refresh" content="3;URL=index.html">"
    print "</HEAD>\n"
    print "<BODY>\n"
    print "<H1>Submission successful</H1>\n"
    print "<P>Your submission has been mailed to the site administrators."
    print "<P>Confirmation has been sent to your email address."
    print "</P>\n"
    print "<P>Thank you.</P>\n"
    print "</BODY>\n";
    print "</HTML>\n"

# Send confirmation email to submittor.

    out2=StringIO.StringIO()
    out2.write("Reply-to: %s\n" % mailrecip)
    out2.write("From: %s\n" % mailrecip)
    out2.write("Subject: %s\n" % subject2)
    out2.write("To: %s\n\n" % `youremail`)
    out2.write("This is confirmation of your request for access\n")
    out2.write("to the K86Tech web site. Your request has been sent\nto ")
    out2.write(A)
    out2.write(" for approval.\n")
    out2.write("This email was automatically generated. The information\n")
    out2.write("you submitted was:\n\n\n")
    out2.write(D)
    mailrecip = youremail

# TEST CODE
#    print "==============<P>\n\n"
#    print "Address: "
#    print A
#    rawtime = clock()
#    sub_time = localtime(rawtime)
#    print subtime
#    cgi.test()
# END TEST CODE

print "</P>\n"
    print "<P>Thank you.</P>\n"
    print "</BODY>\n";
    print "</HTML>\n"

# Send confirmation email to submittor.

    out2=StringIO.StringIO()
    out2.write("Reply-to: %s\n" % mailrecip)
    out2.write("From: %s\n" % mailrecip)
    out2.write("Subject: %s\n" % subject2)
    out2.write("To: %s\n\n" % `youremail`)
    out2.write("This is confirmation of your request for access\n")
    out2.write("to the K86Tech web site. Your request has been sent\nto ")
    out2.write(A)
    out2.write(" for approval.\n")
    out2.write("This email was automatically generated. The information\n")
    out2.write("you submitted was:\n\n\n")
    out2.write(D)
    mailrecip = youremail

# TEST CODE
#    print "==============<P>\n\n"
#    print "Address: "
#    print A
#    rawtime = clock()
#    sub_time = localtime(rawtime)
#    print subtime
#    cgi.test()
# END TEST CODEz


Jason Brashear
jason.brashear@amd.com
Phone: 602-3708
ext.      53708
PCS:    296-4-AMD
                   
> /tutor