Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 85709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:07:55+00:00 2026-05-10T22:07:55+00:00

I’m looking to implement a Contact Us form with Cherrypy and was wondering: Is

  • 0

I’m looking to implement a ‘Contact Us’ form with Cherrypy and was wondering: Is there a good recipe (or a BSD licensed set of code) that I could use instead of reinventing the wheel?

Ideally, this would be Cherrpy 3.1 compatible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:07:55+00:00Added an answer on May 10, 2026 at 10:07 pm

    Well, I had to look into a solution. This works (ugly, and w/o Javascript validation) — using the smtplib lib. Also, note that I stole Jeff’s captcha for this example. Anyone using this will need to change it.

    EDIT: I added validation.

    #!/usr/local/bin/python2.4  import smtplib  import cherrypy  class InputExample:    @cherrypy.expose    def index(self):        return '<html><head></head><body><a href='contactus'>Contact Us</a></body></html>'           @cherrypy.expose         def contactus(self,message=''):                 return ''' <html> <head><title>Contact Us</title> <script type='text/javascript'>     function isNotEmpty(elem)    {       var str = elem.value;       var re = /.+/;       if (!str.match(re))       {          elem.focus();          return false;       }       else       {          return true;       }     }     function isEMailAddr(elem)    {       var str = elem.value;       var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;       if (!str.match(re))       {          return false;       }       else       {          return true;       }    }     function validateForm(form)    {       if (isNotEmpty(form.firstName) && isNotEmpty(form.lastName))       {          if (isNotEmpty(form.email))          {          if (isEMailAddr(form.email))          {             if (isNotEmpty(form.captcha))             {                if ( form.captcha.value=='egnaro'.split('').reverse().join(''))                {                    if (isNotEmpty(form.subject))                      {                         alert('All required fields are found.  We will respond shortly.');                         return true;                      }                }                else                {                    alert('Please enter the word as displayed in the image.');                    return false;                }             }//captcha empty             }          else          {             alert('Please enter a valid email address.');             return false;          } //email          } //email       } //first and last name       alert('Please fill in all required fields.');       return false;    }  </script> </head> <body> <p>%(message)s</p> <form method='POST' action='contactUsSubmitted' onsubmit='return validateForm(this)'>    <label for='firstName'>First Name: </label>    <input type='text' id='firstName' name='firstName' /> (required)<br/>    <label for='lastName'>Last Name: </label>    <input type='text' id='lastName' name='lastName' /> (required)<br/>    <label for='email'>E-mail address: </label>    <input type='text' id='email' name='email' /> (required)<br/>   <label for='phone'>Phone number: </label>    <input type='text' id='phone' name='phone' /> <br/><br/>     <!--THIS NEEDS TO BE CHANGED TO MATCH YOUR OWN CAPTCHA SCHEME!! -->    <label for='captcha'>Enter the word<br /><img alt='rhymes with..' src='http://www.codinghorror.com/blog/images/word.png' width='99' height='26' border='0' /></label><br /> (<a href='http://www.codinghorror.com/blog/sounds/captcha-word-spoken.mp3'>hear it spoken</a>)<br />    <input tabindex='3' id='captcha' name='captcha' /><br /><br />     <label for='subject'>Subject: </label>    <input type='text' id='subject' name='subject' /> (required)<br/>    <label for='body'>Details: </label>    <textarea id='body' name='body'></textarea><br/>  <input type='submit' value='Contact Us' /> </form> </body> </html> '''%{'message':message}           @cherrypy.expose         def contactUsSubmitted(self, firstName, lastName, email, phone, captcha, subject, body ):                 if captcha[::-1] != 'egnaro':                         return self.contactus('Please reenter the word you see in the image.' )                 self.sendEmail('mail2.example.com','mailbox_account','mailbox_pwd','me@example.com',email,                      'Website Contact: '+subject, 'Sender Email: ' + email + '\r\n'                      'Name: ' + firstName + ' ' + lastName + '\r\n' + 'Phone: ' + phone + '\r\n' + body)                 return self.index()          def sendEmail(self,smtpServer, mailboxName, mailboxPassword, contactEmail,senderEmail,subject,body):                 server = smtplib.SMTP(smtpServer) #'smtp1.example.com')                 server.login(mailboxName, mailboxPassword)                  msg = 'To: %(contactEmail)s\r\nFrom: %(senderEmail)s\r\nSubject: %(subject)s\r\nContent-type: text/plain\r\n\r\n%(body)s'                 msg = msg%{'contactEmail':contactEmail,'senderEmail':mailboxName + '@example.com','subject':subject,'body':body}                  server.sendmail(contactEmail, contactEmail, msg) #This is to send it from an internal account to another internal account.                 server.quit()   cherrypy.root = InputExample() cherrypy.config.update ( file = 'development.conf' ) cherrypy.server.start() 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer What about the GLib from GTK? May 11, 2026 at 11:03 am
  • added an answer This is basically a cross site scripting 'feature'. What you… May 11, 2026 at 11:03 am
  • added an answer Don't try to outsmart the VM. The first loop is… May 11, 2026 at 11:03 am

Related Questions

I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I have a web-service that I will be deploying to dev, staging and production.
I'm thinking of starting a wiki, probably on a low cost LAMP hosting account.
I have the following tables in my database that have a many-to-many relationship, which
I'm using the RESTful authentication Rails plugin for an app I'm developing. I'm having
I recently printed out Jeff Atwood's Understanding The Hardware blog post and plan on
I find that getting Unicode support in my cross-platform apps a real pain in
I would like to test a string containing a path to a file for
I'm getting this problem: PHP Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable
I'm an Information Architect and JavaScript developer by trade nowadays, but recently I've been

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.