Creating a simple Python contact form

2019-07-30 08:56发布

问题:

new to Python.

I am trying to make a contact form for my portfolio site using Python. The form has 4 input fields - first_name, last_name, email, and message. My website is hosted by hostgator.com.

I want the form when submitted to simply send me the info supplied in the 4 fields to my specified email.

After lots of searching I see a lot of Django tuts but I just want a simple form using Python.

Any help would be greatly appreciated! - Mike Rossi

#!/usr/bin/python

# Import modules from CGI handling 
import cgi, cgitb, smtplib

cgitb.enable()

# Create instance of FieldStorage
form = cgi.FieldStorage()
print("")

# Get data from fields
first_name = form.getvalue("first_name")
last_name = form.getvalue("last_name")
email = form.getvalue("email")
message = form.getvalue("message")

to = "mike.jacob.rossi@gmail.com"
subject = "Comment from MikeTheDev.com" 
mfrom msg['To'] 
to msg['Subject'] 
form['subject'].value

print("Thanks for contacting me! Get back to you soon,%s. ") % cgi.escape(first_name)