mailScript
## Script (Python) "mailScript"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# Thanks to runyaga, Clemens Robbenhaar
from Products.Formulator.Errors import ValidationError, FormValidationError
# Change the next line to the name of your form, i.e. "context.name_of_my_form"
form = context.email_us_formulator
# Here I initialize a couple of variables
i = 0
myField = []
for field in form.get_fields():
myField.append(field.get_value('title'))
i = i + 1
# Here we'll catch errors
try:
result = context.email_us_formulator.validate_all(context.REQUEST)
except FormValidationError, errlist:
print "I'm sorry. Some of the information you entered was either incorrect or incomplete. Please use the "back" button and fill it in correctly. Thank you!
" for error in errlist.errors: print '' + error.field.get_value('title') + ': '+ error.error_text + '
' print '' return printed # If we didn't get an error, then let's print the page thanking the visitor for filling out the form. if result: print "" print "
\n" print "\n" print "Thank you, " + result['YourName'] + "! We'll be sure to follow up with you shortly!
\n" print "Sincerely,
\n" print "Site Owner\n" print "" # Now, let's see if we can connect to the MailHost. try: mailhost=getattr(context, context.superValues('Mail Host')[0].id) except: raise AttributeError, "Can't find a Mail Host object" # Here we fill in the variables for the email we'll send. Change the values to your needs. mTo = 'owner@yoursite.com' mFrom = result['YourEmail'] mSubj = 'Feedback From Your Web Site!' message = [] message.append("Hi! You've just been sent an email from your Web site!\n") message.append("Sender's name: %s" % result['YourName']) message.append("Sender's phone: %s" % result['YourPhone']) message.append("Sender's email: %s" % result['YourEmail']) message.append("Sender's comments: %s" % result['YourComments']) mMsg = '\n'.join(message) mailhost.send(mMsg, mto=mTo, mfrom=mFrom, subject=mSubj) return printed
" for error in errlist.errors: print '' + error.field.get_value('title') + ': '+ error.error_text + '
' print '' return printed # If we didn't get an error, then let's print the page thanking the visitor for filling out the form. if result: print "" print "
\n" print "\n" print "Thank you, " + result['YourName'] + "! We'll be sure to follow up with you shortly!
\n" print "Sincerely,
\n" print "Site Owner\n" print "" # Now, let's see if we can connect to the MailHost. try: mailhost=getattr(context, context.superValues('Mail Host')[0].id) except: raise AttributeError, "Can't find a Mail Host object" # Here we fill in the variables for the email we'll send. Change the values to your needs. mTo = 'owner@yoursite.com' mFrom = result['YourEmail'] mSubj = 'Feedback From Your Web Site!' message = [] message.append("Hi! You've just been sent an email from your Web site!\n") message.append("Sender's name: %s" % result['YourName']) message.append("Sender's phone: %s" % result['YourPhone']) message.append("Sender's email: %s" % result['YourEmail']) message.append("Sender's comments: %s" % result['YourComments']) mMsg = '\n'.join(message) mailhost.send(mMsg, mto=mTo, mfrom=mFrom, subject=mSubj) return printed