Hi;<br>I have the following code:<br><br>#!/usr/bin/env python<br><br>import smtplib<br>import cgitb; cgitb.enable()<br>import cgi<br>import sys,os<br>sys.path.append(os.getcwd())<br>from login import login<br>import MySQLdb<br>
import re, string<br><br>def mailSpreadsheet():<br>  user, passwd, db, host = login()<br>  database = MySQLdb.connect(host, user, passwd, db)<br>  cursor= database.cursor()<br>  ourEmail1 = '<a href="mailto:anemail@here.com">anemail@here.com</a>'<br>
  ourEmail2 = '<a href="mailto:anotheremail@here.com">anotheremail@here.com</a>'<br>  form = cgi.FieldStorage()<br>  client = form.getfirst('client', '')<br>  clientEmail = form.getfirst('clientEmail', '')<br>
  po = form.getfirst('po', '')<br>  subject = 'Order From Client'<br>  sql = 'select clientEmail from clients where client="%s";' % (string.replace(client, '_', ' '))<br>
  cursor.execute(sql)<br>  clientEmail = cursor.fetchone()[0]<br>  cursor.execute('select * from %s;' % (client))<br>  data = cursor.fetchall()<br>  i = 0<br>  if po != '':<br>    order = 'PO#: %s\n' % (po)<br>
  else:<br>    order = ''<br>  total = 0<br>  for row in data:<br>    i += 1<br>    quantity = form.getfirst('order_' + str(i), '')<br>    if quantity != '0':<br>      sql = 'select * from products p join %s c on p.ID=c.ID where c.ID=%s;' % (client, str(i))<br>
      cursor.execute(sql)<br>      stuff = cursor.fetchone()<br>      price = str(int(stuff[5]*100))<br>      price = price[0:len(price)-2] + '.' + price[-2:]<br>      item, price, description, discount = stuff[2], price, stuff[3], stuff[8]<br>
      order += 'Item #: ' + item + '\tQuantity: ' + quantity + '\tPrice: ' + price + '\tDiscount: ' + str(discount) + '\tDescription: ' + description[:20] + '...\n'<br>      total += float(price) * int(quantity) * (100 - discount)/100<br>
  order += 'TOTAL: $' + str(total)<br>  msg = 'Here is the order from %s:\n\n %s' % (string.replace(client, '_', ' '), order)<br>  session = smtplib.SMTP("localhost")<br>  session.login(user, passwd) # only if it requires auth<br>
  header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n" % subject<br>#  session.sendmail(clientEmail, ourEmail1, header+msg)<br>  session.sendmail(clientEmail, ourEmail2, header+msg)<br><br>mailSpreadsheet()<br>
<br>The email does get sent, and it that happens out of the last line of code. If I surround the code with code to make it print a Web page, it prints without any error. However, as it is, it throws the following error:<br>
<br><p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
 <a href="mailto:me@creative.vi">me@creative.vi</a> and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p><p>[Mon Nov 23 09:52:21 2009] [error] [client 66.248.168.98] Premature end of script headers: mailSpreadsheet.py, referer: <a href="http://globalsolutionsgroup.vi/display_spreadsheet.py">http://globalsolutionsgroup.vi/display_spreadsheet.py</a><br>
</p><p>Why?</p><p>TIA,</p><p>Victor<br></p>