Newbie CGI confusion...

F

Fred Mailhot

I'm trying to write a script that will mail some data from a web-based form
to me, using the "mail" command (under Linux). The following illustrates the
crux of what I'm doing:


#!/usr/bin/python

import os,time,cgi

#################################
# get the data from the form #
#################################
formdata = cgi.FieldStorage()

#################################
# open log file & write header #
#################################
logfile = open('<SOME FILE>','a')
logfile.write('\n*************************** ')
logfile.write(time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.localtime()))
logfile.write(' ***************************\n')


####################
# send data to log #
####################
for name in formdata.keys():
logfile.write(formdata[name].value + '\n')


#########################################
# create shell command to send mail #
#########################################
usrmail = "%s" % formdata['email'].value
usrmesg = "Sender: %s\n\n%s" % (formdata['user'].value,
formdata['comments'].value)
ccaddr = "(e-mail address removed)"
subject = "SMT Website User Feedback"
toaddr = "(e-mail address removed)"

cmdstring = 'mail -c %s -s "%s" -r %s %s' % (ccaddr, subject, usrmail,
toaddr)

os.popen(cmdstring,'w').write(usrmesg)

######## end code snippet #############

So. The script works and the relevant information is mailed, EXCEPT that the
body of the message is included as an attachment of unknown type. When I
execute the shell command from the command line, there's no problem.

Why is Python doing this ?? (or is it something else entirely that I'm not
understanding?)


Many thanks,

Fred.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top